具有子节点元素列表的jackson json反序列化器

具有子节点元素列表的jackson json反序列化器,json,jackson,jackson-databind,Json,Jackson,Jackson Databind,我有一个用于MyObject的反序列化程序,它扩展了StdDeserializer。在其反序列化(JsonParser p,DeserializationContext-ctxt)中,我想将正在反序列化的节点的子节点转换为POJO列表。给定类似json的 { "property1" : "value1", ... "subnode" : [ { "snProperty1" : "value1", "snProperty2" : "value2",

我有一个用于
MyObject
的反序列化程序,它扩展了
StdDeserializer
。在其
反序列化(JsonParser p,DeserializationContext-ctxt)
中,我想将正在反序列化的节点的子节点转换为POJO列表。给定类似json的

{
  "property1" : "value1",
  ...
  "subnode" : [
    {
      "snProperty1" : "value1",
      "snProperty2" : "value2",
      ...
      "snPropertyN" : "valueN"
    },
    { ... }, // other elements like the one above
    { ... }
 ],
  ...
}
还有波乔斯

class Subnode {
    private String snProperty1;
    private String snProperty2;
    ...
    private Stirng snPropertyN;
    // getters and setters
}

class MyObject {
    private String property1;
    ...
    private List<Subnode> subnodes;
    // getters and setters
}

我使用解析器(
p
)编解码器解决了这个问题,没有使用
ObjectMapper

List子节点=新建ArrayList();
if(myObject.hasNonNull(“子节点列表”)){
ObjectCodec codec=p.getCodec();
对于(JsonNode子节点:myObject.get(“子节点列表”)){
add(codec.treeToValue(subnode,subnode.class));
}
}
myObject.setSubnodes(子节点);
objectMapper.convertValue(subnode, new TypeReference<List<Subnode>>() {});
List<Subnode> subnodes = new ArrayList<>();
if (myObject.hasNonNull("subnodeList")) {
    ObjectCodec codec = p.getCodec();
    for (JsonNode subnode : myObject.get("subnodeList")) {
        subnodes.add(codec.treeToValue(subnode, Subnode.class));
    }
}
myObject.setSubnodes(subnodes);