[英]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.