FasterXML / FasterXML/jackson-dataformat-xml

Jackson XML reading mixed sibling nodes "overwriting" issue

Open
#712 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
631
Forks
246
Avg merge
7d 9h
Merged PRs (30d)
13

Description

Jackson seems to be overwriting the older sibling nodes if the order is mixed. See below test case. Seems to be a bug. Thanks.

@JacksonXmlRootElement
data class RootNode(
@JacksonXmlElementWrapper(useWrapping = false)
@JacksonXmlProperty(localName = "NodeA")
val nodeA: List,
@JacksonXmlProperty(localName = "NodeB")
val nodeB: NodeB
)

data class NodeA(
@JacksonXmlProperty(localName = "attr", isAttribute = true)
val attr: String
)

data class NodeB(
@JacksonXmlProperty(localName = "attr", isAttribute = true)
val attr: String
)

class ReadXMLTest {
@Test
fun canRead() {
val xml = """





""".trimIndent()

val xmlMapper = XmlMapper()
xmlMapper.registerModule(kotlinModule())

assertEquals(
RootNode(
listOf(NodeA("123"), NodeA("456")),
NodeB("ABC")
),
xmlMapper.readValue(xml)
)
}
}

This fails with

Expected :RootNode(nodeA=[NodeA(attr=123), NodeA(attr=456)], nodeB=NodeB(attr=ABC))
Actual :RootNode(nodeA=[NodeA(attr=456)], nodeB=NodeB(attr=ABC))

If the XML is like below, then it passes.





Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.