We have a json where for a particular field the data type is different. I want to map it to Java Object using jackson. If the fields are of one type i am able to do it. but for different type unable to find a way.
{
"firstname": "first_name",
"age": "34",
"add_info": [{
"type": "type_a",
"value": "value_a"
},
{
"type": "type_b",
"value": [{
"title": "info_1",
"desc": "desc_1"
},
{
"title": "info_2",
"desc": "desc_2"
}
]
}
]
}
POJO: Basically with this POJO i dont know how to define it
public class AddInfo {
private String type;
private List<Value> value = null;
//getter and setters
}
In the above JSON for add_info field it contains array of JSON object wherein first object value is of type string and second value holds an array of object.
How to handle this kind of situation in Pojo using jackson
List<Value>and write a custom deserializer