Skip to content

XmlMapper fails to parse XML array when the array only has one level #498

Closed
@ericcwlaw

Description

@ericcwlaw

Version used

<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-xml -->
<dependency>
    <groupId>com.fasterxml.jackson.dataformat</groupId>
    <artifactId>jackson-dataformat-xml</artifactId>
    <version>2.13.0</version>
</dependency>

Java versions tested

OpenJDK 1.8, 11 and 16

Test data

<?xml version="1.0" encoding="UTF-8"?>
<result>
  <hello>world</hello>
  <lists>1</lists>
  <lists>2</lists>
  <lists></lists>
  <lists>
    <inner>internal</inner>
    <time>2021-10-27T21:18:46.217Z</time>
  </lists>
  <lists>3</lists>
  <lists>test</lists>
  <lists></lists>
  <single>one</single>
</result>

Incorrect result
by XmlMapper readValue(string, Map.class) method

{
 "hello": "world",
 "single": "one",
 "lists": "test"
}

The array (as "lists" in the test data) contains 6 elements but XmlMapper returns only the last element.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions