FasterXML / FasterXML/jackson-dataformat-xml

Deserialization of heterogeneous list

未關閉
#787 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
3.x
主要語言
Java
星號
631
分支
246
平均合併
7 天 9 小時
30 天內合併 PR
13

描述

### Discussed in https://github.com/FasterXML/jackson-dataformat-xml/discussions/786

Originally posted by **kristofvb** November 19, 2025
Hi,

I have some questions about the following sample:

```
class ParseTest {

@Test
void parse() throws Exception {
var mapper = new XmlMapper();
var root = mapper.readValue("""


somefoo
otherfoo
something very different


""", Root.class);
System.out.println(root);
}

private static class Root {
@JacksonXmlProperty(localName = "foos")
private List foos = new ArrayList<>();

public String toString() {
return "Root{" +
"foos=" + foos +
'}';
}
}

private static class Foo {
@JacksonXmlText
String text;

@JacksonXmlProperty(isAttribute = true)
Integer sequenceNr;

public String toString() {
return "Foo{" +
"text='" + text + '\'' +
", sequenceNr=" + sequenceNr +
'}';
}
}

}
```

- is there a way to make sure the foos list only contains Foo instances for actual foo elements and avoid turning the bar element into a Foo instance?
- is there a way (annotation) to sort the foos list on sequenceNr of the elements? Currently I sort the list in the foos setter (which I omitted in the sample).

Thanks for looking into this.

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。