I have a problem in my custom deserializer in Jackson. I want to access the default serializer to populate the object I am deserializing into. After the population I will do
The DeserializationContext has a readValue() method you may use. This should work for both the default deserializer and any custom deserializers you have.
Just be sure to call traverse() on the JsonNode level you want to read to retrieve the JsonParser to pass to readValue().
public class FooDeserializer extends StdDeserializer {
private static final long serialVersionUID = 1L;
public FooDeserializer() {
this(null);
}
public FooDeserializer(Class t) {
super(t);
}
@Override
public FooBean deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
JsonNode node = jp.getCodec().readTree(jp);
FooBean foo = new FooBean();
foo.setBar(ctxt.readValue(node.get("bar").traverse(), BarBean.class));
return foo;
}
}