Deserialization fails with `XmlMapper` and `DeserializationFeature.UNWRAP_ROOT_VALUE`
See original GitHub issueSimple Test case: https://github.com/dewarim/jackson-xml-debug
Using jackson-dataformat-xml version 2.10.1 @ Java 11
Given: a POJO:
@JacksonXmlRootElement(localName = "Root")
@JsonRootName("Root")
public class Root {
@JsonProperty("id")
String id;
public Root(String id) {
this.id = id;
}
public Root() {
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Root root = (Root) o;
return Objects.equals(id, root.id);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
}
When trying to do
ObjectMapper mapper = new XmlMapper();
mapper.enable(DeserializationFeature.UNWRAP_ROOT_VALUE);
Root deserializedRoot = mapper.readValue(value, Root.class);
I get: com.fasterxml.jackson.databind.exc.MismatchedInputException: Root name ‘id’ does not match expected (‘Root’) for type [simple type, class test.debug.Root] at [Source: (StringReader); line: 1, column: 7] (through reference chain: test.debug.Root[“id”])
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
DeserializationFeature (jackson-databind 2.6.0 API) - FasterXML
Feature that determines whether encountering of JSON null is an error when deserializing into Java primitive types (like 'int' or 'double').
Read more >Jackson json deserialization, ignore root element from json
configure(DeserializationFeature.UNWRAP_ROOT_VALUE, Objects.nonNull(rootAnnotation));. Basically this configuration will help Mapper to identify if provided ...
Read more >Example usage for com.fasterxml.jackson.dataformat.xml ...
List of usage examples for com.fasterxml.jackson.dataformat.xml XmlMapper readValue ... UNWRAP_ROOT_VALUE, true); mapper.configure(DeserializationFeature.
Read more >FasterXML/jackson-databind - Gitter
DeserializationFeature import com.fasterxml.jackson.dataformat.xml. ... Hi, I have an issue with my code and somehow this code below throws a ...
Read more >Jackson Exceptions - Problems and Solutions - Baeldung
The most common Jackson exceptions - the cause of the problem and the solution ... new ObjectMapper(); mapper.enable(DeserializationFeature.
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
Note: as per #485 the behavior WILL CHANGE for 2.13.0 so that:
Second issue may be addressed with a later version (2.14 or later) but first we will want to get back to 2.11 baseline compatibility.
Created https://github.com/FasterXML/jackson-dataformat-xml/issues/485 for that matter. Thank you!