FasterXML / FasterXML/jackson-dataformat-xml

Collection values overwritten if item elements are not contiguous (mixed content)

Đang mở
#363 5 bình luận 6 reaction 0 người được giao Xem trên GitHub
mixed-content will-not-fix
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ả

Looks like we have a bug in the parser. Parsing next simple document leads to data loss.
```

foo1
foo2
bar1
foo3
foo4

```
Expected result: `foo` java-property contains list of 4 values.
Actual result: `foo` java-property contains list of 2.

Setter for `foo` property is called two times for every tags group: `foo1, foo2` and `foo3, foo4`. Second setter call overrides data gathered by the first call. As result parsing result contains `foo` list as `foo3, foo4` instead of expected `foo1, foo2, foo3, foo4`.
Here is a java-code to reproduce the issue.
```
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlCData;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import java.util.List;

@JacksonXmlRootElement(localName = "data")
class Data {
@JacksonXmlCData
@JacksonXmlElementWrapper(useWrapping = false)
@JacksonXmlProperty
private List foo;

@JacksonXmlCData
@JacksonXmlElementWrapper(useWrapping = false)
@JacksonXmlProperty
private List bar;

public List getFoo() {
return foo;
}

public void setFoo(List foo) {
this.foo = foo;
}

public List getBar() {
return bar;
}

public void setBar(List bar) {
this.bar = bar;
}
}

public class Foo {
public static void main(String[] args) throws JsonProcessingException {
String xml = ""
+ ""
+ " foo1"
+ " foo2"
+ " bar1"
+ " foo3"
+ " foo4"
+ "";

XmlMapper m = new XmlMapper();
Data data = m.readValue(xml, Data.class);

System.err.println(data.getFoo()); // Expected ["foo1", "foo2", "foo3", "foo4"] but ["foo3", "foo4"] given.
}
}
```

jackson-dataformat-xml version: 2.10.0

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.