I have the following class with a property "key" that maps to 2 different JSON
fields
public class A {
@JsonAlias("Key")
private String key;
@JsonProperty("NewKey")
private void unpackNewKey(Map<String, String> NewKey) {
key = NewKey.get("value");
}
}
Here is the JSON to deserialize.
{
"NewKey": {
"value": "newkey",
},
"Key": "key"
}
If I deserialize the above json to A.class
ObjectMapper mapper = new ObjectMapper();
A a = mapper.readValue(json, A.class)
What would be the value of the a.key
? will it be newkey
or key
? Trying to understand how jackson handles conflict. Can I specify the order? for example, if I want the key
to always map to NewKey
if both Key
and NewKey
exist in the json, what should I do?