We are working with a REST service that provides json that will consist of some standard properties, as well as a number of dynamic properties.
For example:
{
id: 123,
name: "some name",
custom_name: "Some value",
some_other_custom_name: "Some other value",
}
Ideally, I'd like to have the class designed as follows:
public class MyObject{
@JsonProperty int id;
@JsonProperty String name;
private Map<String, String> customVals;
public int getId(){
return id;
}
public String getName(){
return name;
}
public String getCustomVal(String key){
return customVals.get(key);
}
}
Is there any way to convince Jackson to push the custom values into the Map (or achieve equivalent functionality)?
Right now, I'm just deserializing the whole object into a Map, and wrapping that in my business object, but it's not nearly as elegant as it would be if the deserialization would take care of it.