3

I have a class which is annotated with

@JsonDeserialize(using = CustomDeserializer.class)

now I would like to use also default deserializer in CustomDeserializer.class

@Override
public CustomObject deserialize(JsonParser jp, DeserializationContext ctxt)
{
  if(someCondition){
     return useDefaultDeserialization(jp); // default
  } else {
     return new ObjectMapper().readValue(jp..., CustomObject.class); // custom
  }
}

How can I invoke default deserializer?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
PDS
  • 562
  • 3
  • 13
  • 27
  • 2
    You should be able to find an answer here: [How do I call the default deserializer from a custom deserializer in Jackson](https://stackoverflow.com/questions/18313323/how-do-i-call-the-default-deserializer-from-a-custom-deserializer-in-jackson) – Ryan Leach May 17 '18 at 10:27
  • No, unfortunately this does not work. I'm getting StackOverflowError because all the time custom deserializer is invoked when -> mapper.readValue((String) jp.getCurrentLocation().getSourceRef(), CustomObject.class) – PDS May 17 '18 at 10:45
  • What exactly do you want to achieve? Can you provide a _concrete_ example? – cassiomolin May 17 '18 at 11:56
  • @PDS , check the Accepeted Answer in the link Ryan posted. – Jeryl Cook May 17 '18 at 16:01
  • I can't believe this is as difficult as it is... – Uncle Long Hair Jun 18 '19 at 14:51

0 Answers0