I need to deserialize a Json response
response: {
speed: 40,
distance: 20,
time: 3
}
into 3 different objects, that is
Class Speed implements Base{
int speed;
}
Class Distance implements Base{
int distance;
}
Class Time implements Base{
int time;
}
This is what I have so far,
@jsondeserialize(using = customdeserializer.class)
Class Response implements Base{
...
}
Class customdeserializer extends JsonDeserializer<List<Base>> {
@Override
public List<Base> deserialize(...) {
//read Jsonparser
// construct objects for Speed, Time and Distance
//return
}
}
Class Context {
public List<Base> converter(..) {
ObjectMappper mapper = new ObjectMapper()
List<Base> params = objectMapper.readValue(jsonValue, new TypeReference<List<Response>>() { });
return params;
}
}
ISSUE: My customserializer is never getting called. I verified this by having a debug point
I am using FasterXML Jackson
Any idea how to do this using custom deserializer.