jackson-databind icon indicating copy to clipboard operation
jackson-databind copied to clipboard

Exception while deserializing with @JsonRootName

Open pritibiyani opened this issue 6 years ago • 15 comments

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
}

pritibiyani avatar Feb 11 '19 12:02 pritibiyani