Skip to content

Cannot deserialize an unwrapped list of elements - @JacksonXmlElementWrapper(useWrapping) missing? #305

@tom-mayer

Description

@tom-mayer

when I try to parse the following XML I get an error with Jackson:

<root>
  <aCollection>
    <language xml:lang="en">
      <entry id="1" value="foo"/>
      <entry id="2" value="bar"/>
      <entry id="3" value="blah"/>
    </language>
  </aCollection>
</root>

The classes I use are:

@Data
@JacksonXmlRootElement(localName = "root")
public class RootDTO {
  @JacksonXmlProperty(localName = "aCollection")
  private CollectionDTO collection;
}

@Data
public class CollectionDTO {
  @JacksonXmlProperty(localName = "language")
  LanguageDTO language;
}

@Data
public class LanguageDTO {
  @JacksonXmlProperty(localName = "entry")
  EntryDTO[] entries;
}

@Data
public class EntryDTO {

  @JacksonXmlProperty(isAttribute = true)
  private String id;

  @JacksonXmlProperty(isAttribute = true)
  private String value;

}

The error is:
Can not instantiate value of type [simple type, class com.tinkerdesk.viewer.model.DTO.EntryDTO] from JSON String; no single-String constructor/factory method

If I remove the array brackets it works but of course only parses the first entry element. I found that I should maybe use @JacksonXmlElementWrapper(useWrapping = false) on top of EntryDTO[] entries; since the elements are not wrapped. However this does not comile for me because there is no useWrapping in the com.fasterxml.jackson.xml.annotate.JacksonXmlElementWrapper. My Jackson core version is 2.9.6 and xml-databind 0.6.2. Is there now a newer way to do this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions