Skip to content

Commit 7955dae

Browse files
committed
Added failing test and fix or issue FasterXML#646
1 parent ae1bc1a commit 7955dae

File tree

2 files changed

+89
-1
lines changed

2 files changed

+89
-1
lines changed

src/main/java/com/fasterxml/jackson/dataformat/xml/util/TypeUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class TypeUtil
1111
public static boolean isIndexedType(JavaType type)
1212
{
1313
Class<?> cls = type.getRawClass();
14-
if (type.isContainerType() || type.isIterationType()) {
14+
if (type.isContainerType() || type.isIterationType() || cls == Iterable.class) {
1515
// One special case; byte[] will be serialized as base64-encoded String, not real array, so:
1616
// (actually, ditto for char[]; thought to be a String)
1717
if (cls == byte[].class || cls == char[].class) {
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package com.fasterxml.jackson.dataformat.xml.lists;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import com.fasterxml.jackson.annotation.JsonProperty;
7+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
8+
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
9+
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
10+
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
11+
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
12+
13+
public class IterableCollectionBuilder646Test extends XmlTestBase {
14+
15+
@JsonDeserialize(builder = Parent.Builder.class)
16+
@JacksonXmlRootElement(localName = "parent")
17+
static class Parent {
18+
private final List<Child> children;
19+
20+
private Parent(List<Child> children) {
21+
this.children = children;
22+
}
23+
24+
@JsonProperty("child")
25+
@JacksonXmlElementWrapper(useWrapping = false)
26+
public List<Child> getChildren() {
27+
return children;
28+
}
29+
30+
static class Builder {
31+
private final List<Child> children = new ArrayList<>();
32+
33+
@JsonProperty("child")
34+
@JacksonXmlElementWrapper(useWrapping = false)
35+
public Builder children(Iterable<Child> children) {
36+
for (Child c : children) {
37+
this.children.add(c);
38+
}
39+
return this;
40+
}
41+
42+
public Parent build() {
43+
return new Parent(children);
44+
}
45+
}
46+
}
47+
48+
@JsonDeserialize(builder = Child.Builder.class)
49+
@JacksonXmlRootElement(localName = "child")
50+
static class Child {
51+
private final String id;
52+
53+
public Child(String id) {
54+
this.id = id;
55+
}
56+
57+
@JsonProperty("id")
58+
public String getId() {
59+
return id;
60+
}
61+
62+
static class Builder {
63+
private String id;
64+
65+
@JsonProperty("id")
66+
public Builder id(String id) {
67+
this.id = id;
68+
return this;
69+
}
70+
71+
public Child build() {
72+
return new Child(id);
73+
}
74+
}
75+
}
76+
77+
// -- Test Methods --//
78+
private final XmlMapper MAPPER = newMapper();
79+
80+
public void testIssue646() throws Exception {
81+
final String XML = "<parent><child><id>1</id></child></parent>";
82+
Parent parent = MAPPER.readValue(XML, Parent.class);
83+
assertNotNull(parent);
84+
assertNotNull(parent.getChildren());
85+
assertEquals(1, parent.getChildren().size());
86+
87+
}
88+
}

0 commit comments

Comments
 (0)