I have a json in following format, where in key represents the attribute type and value represents the value of that attribute.
{ "attributes":
[
{
"key":"name",
"value":"Archit"
},
{
"key":"website",
"value":"stackoverflow"
},
{
"key":"languages",
"value":[
"python",
"java",
"c++"
]
}
]
}
I am trying to map it to an following java object using jackson :
public class Attributes {
List<Attribute> attributes;
}
public abstract class Attribute {
String key;
}
public class SingleValuedAttribute extends Attribute{
String value;
}
public class MultiValuedAttribute extends Attribute{
List<String> value;
}
ObjectMapper mapper = new ObjectMapper();
Attributes attributes = mapper.readValue(new File(jsonFilePath), Attributes.class);
I tried having a look at polymorphic deserialization but that required type info in the json object, which doesn't exist in my json ?
Any tips on how to do this ?
PS: I can't change the json format. The list of keys is not bounded/limited.