Exception while deserializing with @JsonRootName
See original GitHub issueDesirialization 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
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:14 (5 by maintainers)
Top Results From Across the Web
Jackson json deserialization, ignore root element from json
UNWRAP_ROOT_VALUE configured', it unwrap all jsons, eventhough my class in not annotated with @JsonRootName(value = "rootTagInJson"), isn't weired. I want to ...
Read more >Jackson Exceptions - Problems and Solutions - Baeldung
When we try to deserialize a JSON String to Zoo instance, it throws the JsonMappingException: Can Not Construct Instance Of:
Read more >Using @JsonTypeInfo annotation to handle polymorphic types
In cases where polymorphic types are persisted to JSON, there's no way for Jackson to figure out the right type during deserialization.
Read more >[Solved]-Jackson xml and json root element-Springboot
In XML you want a list of RestObject and in JSON you want a list whose elements wrap ... you would need a...
Read more >DeserializationFeature (jackson-databind 2.9.0 API) - FasterXML
Feature is enabled by default, so that unknown Object Ids will result in an exception being thrown, at the end of deserialization. Since:...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@pritibiyani No, not really, XML and JSON are NOT identical structurally: there is impedance regarding names. So, following might represent identical logical content:
and so any “root name” in case of XML must be for
point
; and since XML does not allow more than one root element, one can never match anything else.The original reason to support
@JsonRootName
(and unwrapping) for json was, however, that some legacy json libraries would map such logical content aswhich is redundant and clumsy, but is easier to convert to/from xml.
I am bit wary of either changing definitions of features involved, or adding a single-use feature. But I can see the point of request itseld.
I will have to think more about handling here: a significant part of hesitation is the fact that I don’t know how involved it would be to allow original code to work as shown, for both XML and JSON cases.
I’ll tag this as 2.10 since behavioral change is involved.