Skip to content

Commit 1e41752

Browse files
authored
Add passing test for #853 (fixed as dup of #615) (#854)
1 parent f95f0bc commit 1e41752

2 files changed

Lines changed: 84 additions & 0 deletions

File tree

release-notes/VERSION

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ Version: 3.x (for earlier see VERSION-2.x)
125125
(implemented by @cowtowncoder, w/ Claude code)
126126
#849: Allow writing Comments in Document Prolog (before root element)
127127
(implemented by @cowtowncoder)
128+
#853: `InvalidDefinitionException` on classes using
129+
`@JacksonXmlElementWrapper` and `@JacksonXmlProperty`
130+
(reported by @soc)
131+
(fix by @cowtowncoder, w/ Claude code)
128132

129133
3.1.2 (11-Apr-2026)
130134
3.1.1 (27-Mar-2026)
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package tools.jackson.dataformat.xml.deser;
2+
3+
import java.util.List;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
import com.fasterxml.jackson.annotation.JsonCreator;
8+
import com.fasterxml.jackson.annotation.JsonProperty;
9+
10+
import tools.jackson.dataformat.xml.XmlTestUtil;
11+
import tools.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
12+
import tools.jackson.dataformat.xml.annotation.JacksonXmlProperty;
13+
14+
import static org.junit.jupiter.api.Assertions.assertEquals;
15+
import static org.junit.jupiter.api.Assertions.assertNotNull;
16+
17+
// [dataformat-xml#853] InvalidDefinitionException on classes using
18+
// @JacksonXmlElementWrapper and @JacksonXmlProperty on a field when class
19+
// has a matching args-constructor (e.g., record).
20+
public class ElementWrapperCreator853Test extends XmlTestUtil
21+
{
22+
// Class version: field-annotated only, no @JsonCreator, single args ctor
23+
static class GroupDto {
24+
@JacksonXmlElementWrapper(localName = "users")
25+
@JacksonXmlProperty(localName = "user")
26+
private List<String> users;
27+
28+
private String name;
29+
30+
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
31+
public GroupDto(@JsonProperty("users") List<String> users,
32+
@JsonProperty("name") String name) {
33+
this.users = users;
34+
this.name = name;
35+
}
36+
37+
public List<String> getUsers() { return users; }
38+
public String getName() { return name; }
39+
}
40+
41+
// Record version: most direct form
42+
public record GroupRecord(
43+
@JacksonXmlElementWrapper(localName = "users")
44+
@JacksonXmlProperty(localName = "user")
45+
List<String> users,
46+
String name
47+
) {}
48+
49+
private static final String XML =
50+
"<GroupDto>"
51+
+ "<users>"
52+
+ "<user>A</user>"
53+
+ "<user>B</user>"
54+
+ "</users>"
55+
+ "<name>g1</name>"
56+
+ "</GroupDto>";
57+
58+
@Test
59+
public void testDeserializeClass() throws Exception
60+
{
61+
GroupDto result = newMapper().readValue(XML, GroupDto.class);
62+
assertNotNull(result.getUsers());
63+
assertEquals(2, result.getUsers().size());
64+
assertEquals("A", result.getUsers().get(0));
65+
assertEquals("B", result.getUsers().get(1));
66+
assertEquals("g1", result.getName());
67+
}
68+
69+
@Test
70+
public void testDeserializeRecord() throws Exception
71+
{
72+
String xml = XML.replace("GroupDto", "GroupRecord");
73+
GroupRecord result = newMapper().readValue(xml, GroupRecord.class);
74+
assertNotNull(result.users());
75+
assertEquals(2, result.users().size());
76+
assertEquals("A", result.users().get(0));
77+
assertEquals("B", result.users().get(1));
78+
assertEquals("g1", result.name());
79+
}
80+
}

0 commit comments

Comments
 (0)