I'm trying to extend the Jackson default deserialization to assign a placeholder object to the fields of my domain object when they are set to null explicitly in the json. I'm using Spring Boot + Spring Data. I searched a lot for the best way to do it and I believe a custom deserializer is what I want. I'm open for suggestions about that too, but my actual question is about how to use the default deserialization and handle the explicit null assignments myself. This is where I'm stuck (in MyItemDeserializer):
@Override
public Item deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
throws IOException, JsonProcessingException
{
Item item = (Item) defaultDeserializer.deserialize(jsonParser, deserializationContext);
JsonNode root = jsonParser.readValueAsTree();
// traverse the tree to handle {"something":null}
return item;
}
Obviously after the default deserializer processed the jsonParser object readValueAsTree
returns null. Is there a way to have the json as a tree (or anything else) after the default deserialization?