How do I call the default deserializer from a custom deserializer in Jackson

前端 未结 11 1132
野趣味
野趣味 2020-11-22 14:26

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

11条回答
  •  渐次进展
    2020-11-22 14:59

    Here is a oneliner using ObjectMapper

    public MyObject deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
        OMyObject object = new ObjectMapper().readValue(p, MyObject.class);
        // do whatever you want 
        return object;
    }
    

    And please: There is really no need to use any String value or something else. All needed information are given by JsonParser, so use it.

提交回复
热议问题