I have a class-1 member variable => Map<(class-2) object, Boolean>. The jackson is not able to de-serialize the Map, and hence returning the Null object in an API.
I have tried making my own custom de-serializer but it's not working well for me.
Class-1
private String contact;
@JsonDeserialize(keyUsing = MyCustomDeserializer.class)
private Map<class-2, Boolean> events;
private String delivery;
Class-2
private static final long serialVersionUID = 1L;
Integer id;
String age;
String grp;
Custom Deserializer
public class MyCustomDeserializer extends KeyDeserializer {
private Log log = LogFactory.getLog(getClass());
@Override
public Class-2 deserializeKey(String key, DeserializationContext ctxt) throws IOException, JsonProcessingException {
log.debug(key); // not getting any print in logs
return null; // not sure about it
}
}
Also, not sure about where to add this code and which class should be in this below code.
final ObjectMapper objectMapper = new ObjectMapper();
SimpleModule simpleModule = new SimpleModule();
simpleModule.addKeyDeserializer(which class??, new MyCustomDeserializer());
objectMapper.registerModule(simpleModule);