I know a similar question already exists (Jackson - Deserializing to a Different Type) but the answer there does not help me. The old JSON files are already in production and cannot be changed.
I have a regular application with old POJOs. Now I have new POJOs and currently to support the old files I am deserializing to the old POJOs and converting manually to the new ones. I would like to write the conversion directly into a Jackson deserializer but I am having trouble. In the past I have writen a simple Jackson module for serializing and deserializing certain types and I have some basic knowledge of Jackson.
I have something like:
public class MyModule extends com.fasterxml.jackson.databind.module.SimpleModule
public MyModule() {
super("MyModule", Version.unknownVersion());
addDeserializer(OldPojo.class, new JsonDeserializer<NewPojo>() {
@Override
public NewPojo deserialize(JsonParser p, DeserializationContext ctxt) {
// convert and return new pojo
}
}
// others deserializers ...
}
}
Would this approach be possible? And what am I doing wrong? Lots of thanks.