FasterXML / FasterXML/jackson-dataformat-xml

Deserialization of heterogeneous list

Đang mở
#787 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
3.x
Ngôn ngữ chính
Java
Star
631
Fork
246
Merge trung bình
7 ngày 9 giờ
Pull request đã merge (30 ngày)
13

Mô tả

### 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.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.