I have a JSON structure where the key and value are stored like this
[
{
"key": "firstName",
"value": "John"
},
{
"key": "lastName",
"value": "Smith"
}
]
I would like to deserialize the array so that each key is a property name, and the appropriate value assigned.
public class Customer {
private String firstName;
private String lastName;
public String getFirstName() {
return this.firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return this.lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
I have thought of creating a custom deserializer to accept an array of customer attributes, and manually setting each property based on the attribute name. My concern is this approach could be become brittle with the addition of more properties, and is not maintainable in the long term.
Does anyone know of any Jackson annotations that I may have overlooked that would aid in this deserialization?