Desirialization does not work when there are multiple nodes available at same level as value provided in the JsonRootName
Note: Wrapper is configured with following:
objectMapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
Class:
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonRootName(value = "response")
public class UserProfile {
String name;
String link;
}
Input JSON (which works):
{
"response": {
"name": "User one:",
"link": "Some Link"
}
}
Input JSON (which does not work)
{
"response": {
"name": "User one:",
"link": "Some Link"
},
"apiVersion" : 1.0
}
Adding a wrapper for with fields response
and apiVersion
wouls solve this problem which would defeat the purpose of using tag JsonRootName
How to deserialize when there is more than one field at root level (without using another wrapper class) ?