杰克逊自定义解串器委托恢复为默认值 [英] Jackson custom deserialiser delegate back to default one
本文介绍了杰克逊自定义解串器委托恢复为默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在自定义的Jackson解串器中,是否可以将某些属性委派回默认的解串器?
In a custom Jackson deserialiser, is there a way to delegate certain properties back to the default deserialiser?
@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.
}
p.s.我确实需要自定义反序列化器,并且不能使用类型注释.
p.s. I do need custom deserialiser and cannot use type annotations.
推荐答案
您可以使用以下代码来实现这一目标.
You can use following code to achieve this.
JsonParser parser = nodeToDelegate.traverse();
parser.setCodec(jp.getCodec());
parser.readValueAs(<Type>.class);
这篇关于杰克逊自定义解串器委托恢复为默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文