I need to provide custom deserialization of the Map and then each Property object has to be serialized by default serializer. This map is part of another object:
class PropertiesHolder {
Map<String, Property> properties;
}
I've defined mixin for the PropertiesHolder class:
class PropertiesHolderMixIn {
@JsonSerialize(using=PropertiesSerializer.class)
@JsonDeserialize(using=PropertiesDeserializer.class)
Map<String, Property> properties;
}
I have also mixin for Property class. The ObjectMapper initialization:
ObjectMapper mapper = new ObjectMapper();
SimpleModule module = new SimpleModule();
module.setMixInAnnotation(Property.class, PropertyMixIn.class);
module.setMixInAnnotation(PropertiesHolder.class, PropertiesHolderMixIn.class);
mapper.registerModule(module);
My deserializer:
class PropertiesDeserializer extends JsonDeserializer<Map<String, Property>> {
public Map<String, Property> deserialize(JsonParser jp, DeserializationContext ctxt) throws ... {
ArrayNode node = (ArrayNode) jp.readValueAsTree();
for (int i = 0, size = node.size() ; i < size ; i++) {
ObjectNode jn = (ObjectNode) node.get(i);
String key = jn.get("propertyName").textValue();
String value = jn.get("propertyValue").toString();
... HERE I need to call registered deserializer for Property class over value ...
}
}
}
I've looked at How do I call the default deserializer from a custom deserializer in Jackson, but it doesn't work form me ... it ends with NPE. Also the solution described in the post creates deserializer for the outer class which for me is defined as mixin and I don't want to create deserializer for this class.
Please, point me to a solution. Where can I get default deserializer for the Property object?
Thanks