本文介绍了将JsonNode转换为对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个外部库提供的JsonNode.我需要将此JsonNode转换为其POJO表示形式.

I've got a JsonNode that is provided by an external library. I need to convert this JsonNode into it's POJO representation.

我见过这样的方法:

mapper.readValue(jsonNode.traverse(), MyPojo.class);

但是我对这种解决方案不是很满意. traverse()实际上将我的JsonNode转换为String表示形式,然后反序列化为POJO.在这种情况下,性能对我来说是个问题.

But I'm not very happy with this sollution. traverse() will actually convert my JsonNode into a String representation before it is deserialized into a POJO. The performance is an issue for me in this case.

还有其他方法吗?

谢谢

推荐答案

也许您正在寻找:

mapper.convertValue(jsonNode, MyPojo.class)

这篇关于将JsonNode转换为对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-05 11:15