FasterXML/jackson-dataformat-xml — Issue #17: Deserializing when using custom wrapper element
Author: mortenoh
Created: 2012-02-29 07:20:58+00:00
State: open

I'm having some issues deserializing a class that uses a @JacksonXmlElementWrapper.

This how my class looks:

```java
@JacksonXmlRootElement( localName = "person", namespace ="http://example.org/person" )
public class Person
{
@JacksonXmlProperty( isAttribute = true )
private String id;

private String name;

private Integer age;

@JacksonXmlElementWrapper(localName = "notes")
@JacksonXmlProperty( localName = "note" )
private List notes = new ArrayList();

// getters, setters, etc
}
```

And this gets serialized fine with:

```java
Person p = new Person( "Name", 30 );
p.getNotes().add( "This is note #1" );
p.getNotes().add( "This is note #2" );

ObjectMapper xmlMapper = new XmlMapper();
String xml = xmlMapper.writeValueAsString( p );
```

This gives me something like:

```xml

Name
30

This is note #1

This is note #2

```

But, when I now try and deserialize this using:

```java
Person p = xmlMapper.readValue( xml, Person.class );
```
I get:

```java
Exception in thread "main"
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:
Unrecognized field "notes" (Class Person), not marked as ignorable
at [Source: java.io.StringReader@5c1fe88d; line: 1, column: 169]
(through reference chain: Person["notes"])
at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:51)
at com.fasterxml.jackson.databind.DeserializationContext.reportUnknownProperty(DeserializationContext.java:526)
at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:651)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:771)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:291)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:99)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2532)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:1774)
```