Jackson Deserializer for one custom field?

I believe that we need our own deserializer to do something specific with one field of our class. As soon as I do this, I am now responsible for deserializing all the other fields. Is there a way for Jackson to deserialize all fields except the ones I'm interested in here?

public class ThingDeseralizer extends StdDeserializer<Thing> {
    @Override
    public Thing deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
        ObjectCodec oc = p.getCodec();
        JsonNode node = oc.readTree(p);

        String special = node.get("special").asText();

        Thing thing = new Thing()
        thing.doSomethignWithSpecial(special)
        return thing;
    }
}

Thanx

+4
source share
1 answer

Add annotation to the field in POJO @JsonDeserialize(using = ThingDeseralizer.class).

This will tell Jackson how to deserialize this particular field, the rest will all go by default.

+6
source

All Articles