I have a JSON like the following:
{
systemId: 7
name: "Phil"
data: "XYZ"
pointers: [
{
systemId: 23
name: "Peter"
},
{
systemId: 27
name: "Jeroen"
}
]
}
In the POJO equivalent of the above JSON, all fields are final. Now, during deserialization, I want to have the ability to modify the systemId field before it is set on the POJO by Jackson. Further, the changed systemId would actually be provided by an stateful object as a function of the current systemId from the JSON. For example, the new systemId to be set on the deserialized POJO might be provided by an instance of a class such as follows:
public class SystemIdProvider {
...
public long getNewSystemId(long oldSystemId) {
// do something with the oldSystemId and
// the current state of this object to get the newSystemId
return newSystemId;
}
}
Is there a way I can supply an instance of the above class to Jackson when it is deserializing a JSON, and to make Jackson use this object to get the newSystemId before setting it on the POJO's it creates?
Please note that the JSON above is just a small snippet of the actual JSON and hence might contain hundreds of such objects as above. And I want to provide a NEW instance of the SystemIdProvider class per deserialization as the "state" it maintains is also based on the systemIds it has encountered thus far. Thus it needs to start with a clean state for every deserialization.
Any inputs are appreciated.