如何将JsonNode实例转换为实际的Pojo [英] How to convert a JsonNode instance to an actual pojo

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

问题描述

在代码的特定位置,我已经将一个表示为字符串的JSON文档解析为 JsonNode ,因为我还不知道实际的目标pojo类类型.

At a certain point in my code, I have parse a JSON document, represented as a string, to a JsonNode, because I don't know yet the actual target pojo class type.

现在,一段时间后,我知道了pojo的 Class 实例,我想将此 JsonNode 转换为该类的实际pojo(用注释正确的 @JsonProperty 注释).能做到吗?如果可以,怎么办?

Now, some time later, I know the Class instance of the pojo and I want to convert this JsonNode to an actual pojo of that class (which is annotated with the proper @JsonProperty annotations). Can this be done? If so, how?

我正在使用Jackson 2.10.x.

I am working with Jackson 2.10.x.

推荐答案

在这种情况下,您可以使用两种方法:

In this case you can use two methods:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆