简体   繁体   English

Jackson 自定义反序列化器委托恢复为默认值

[英]Jackson custom deserialiser delegate back to default one

In a custom Jackson deserialiser, is there a way to delegate certain properties back to the default deserialiser?在自定义的 Jackson 反序列化器中,有没有办法将某些属性委托回默认的反序列化器?

@Override
public final T deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    ObjectNode node = jp.getCodec().readTree(jp);

    T type = createType();
    //custom deserialise some fields here
    ...

    // Is there a way to delegate everything else back to Jackson?

    ObjectNode nodeToDelegate = node.get("someField");
    // delegate back to jackson and deserialise into `type`
    // nodeToDelegate can be anything - Number / Object / Array / etc.
}

ps I do need custom deserialiser and cannot use type annotations. ps 我确实需要自定义反序列化器并且不能使用类型注释。

You can use following code to achieve this.您可以使用以下代码来实现这一点。

JsonParser parser = nodeToDelegate.traverse();
parser.setCodec(jp.getCodec());
parser.readValueAs(<Type>.class);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何委托杰克逊的自定义反序列化器中的默认反序列化? - How to delegate to default deserialization in custom deserializer in Jackson? 如何将列表的Jackson自定义反序列化器添加到模块中? - How do i add a Jackson custom deserialiser of a list to a module? Jackson Deserialiser:在现场使用@JsonCreator 和@JsonProperty? - Jackson Deserialiser : use @JsonCreator AND @JsonProperty on field? 自定义反序列化器以解析复杂的Json - Custom Deserialiser to parse complex Json 带有@JsonProperty 的自定义序列化器和反序列化器 - Java - Custom serialiser and deserialiser with @JsonProperty - Java Jackson序列化和@JsonValue:返回默认行为 - Jackson serialization and @JsonValue : back to the default behavior JSON反序列化器可在POJO中设置自定义属性 - JSON deserialiser to set custom properties in POJO 使用Jackson进行自定义反序列化:扩展默认反序列化器 - Custom deserialization with Jackson: extend default deserializer 使用Jackson将默认序列化程序应用于自定义序列化程序中的属性 - Apply default serializer to properties in custom serializer with Jackson 如何在自定义序列化程序中访问默认的 jackson 序列化 - How to access default jackson serialization in a custom serializer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM