1

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) ?

Priti Biyani
  • 414
  • 5
  • 11
  • So, your question is: what is the purpose of `@JsonRootName`?? – Carlitos Way Feb 11 '19 at 18:35
  • How to deserialize this type of structure without using another wrapper? – Priti Biyani Feb 12 '19 at 03:13
  • Well, I don't know if your can do that ... what you're expecting about `@JsonRootName` using the second type of input (the one that does not work): deserializes the response object and skip the `apiVersion` attribute? – Carlitos Way Feb 12 '19 at 17:32

0 Answers0