Java 将 JsonNode 转换为对象
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25024999/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert JsonNode into Object
提问by pmartin8
I've got a JsonNode that is provided by an external library. I need to convert this JsonNode into it's POJO representation.
我有一个由外部库提供的 JsonNode。我需要将此 JsonNode 转换为它的 POJO 表示。
I've seen methods like this:
我见过这样的方法:
mapper.readValue(jsonNode.traverse(), MyPojo.class);
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.
但我对这个解决方案不是很满意。traverse() 实际上会在我的 JsonNode 反序列化为 POJO 之前将其转换为 String 表示。在这种情况下,性能对我来说是个问题。
Any other way of doing it?
还有其他方法吗?
Thanks
谢谢
回答by dnault
Perhaps you're looking for:
也许您正在寻找:
mapper.convertValue(jsonNode, MyPojo.class)