-
-
Notifications
You must be signed in to change notification settings - Fork 230
Closed
Milestone
Description
Using Jackson 2.9.7, it fails to deserialize xml elements if they are in a specific order. Changing order works around the problem. The 'problematic' elements are in a collection element. Unboxing those works around the problem as well. See this test class:
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.junit.Before;
import org.junit.Test;
import java.io.IOException;
import java.util.List;
public class JacksonTest {
private ObjectMapper mapper;
@Before
public void setUp() {
mapper = new XmlMapper(new JacksonXmlModule());
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.UPPER_CAMEL_CASE);
}
@Test
public void testOrder1() throws IOException {
mapper.readValue(order1Xml(), Customer.class);
}
@Test
public void testOrder2() throws IOException {
mapper.readValue(order2Xml(), Customer.class);
}
@Test
public void testAddressAsParent() throws IOException {
mapper.readValue(addressAsParentXml(), Address.class);
}
@Data
public static class Customer {
@JacksonXmlElementWrapper(localName = "Customer", useWrapping = false)
@JacksonXmlProperty(localName = "Address")
private final List<Address> address;
}
@Data
public static class Address {
private final String stateProv;
private final CountryName countryName;
}
@Data
@NoArgsConstructor
public static class CountryName {
private String code;
@JacksonXmlText
private String name;
}
private String order1Xml() {
return ""
+ "<Customer>"
+ " <Address>\n"
+ " <StateProv StateCode=\"DE-NI\">Niedersachsen</StateProv>\n"
+ " <CountryName Code=\"DE\">Deutschland</CountryName>\n"
+ " </Address>\n"
+ "</Customer>"
;
}
private String order2Xml() {
return ""
+ "<Customer>"
+ " <Address>\n"
+ " <CountryName Code=\"DE\">Deutschland</CountryName>\n"
+ " <StateProv StateCode=\"DE-NI\">Niedersachsen</StateProv>\n"
+ " </Address>\n"
+ "</Customer>"
;
}
private String addressAsParentXml() {
return ""
+ " <Address>\n"
+ " <CountryName Code=\"DE\">Deutschland</CountryName>\n"
+ " <StateProv StateCode=\"DE-NI\">Niedersachsen</StateProv>\n"
+ " </Address>\n"
;
}
}
Expected behavior: all tests should pass.
Metadata
Metadata
Assignees
Labels
No labels