Skip to content

Commit aa1c5dd

Browse files
authored
Merge branch '3.x' into tatu-claude/3.2/559-fix-xml-text-vs-creator
2 parents f356b75 + 45c7e7a commit aa1c5dd

4 files changed

Lines changed: 112 additions & 0 deletions

File tree

release-notes/CREDITS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ Sam Kruglov (@Sam-Kruglov)
6666
`FromXmlParser.getRootElementName()`)
6767
(3.2.0)
6868

69+
Alexios Pantavos (@AlexiosP)
70+
* Reported #514: Deserialisation to polymorphic class using `JsonTypeInfo.Id.DEDUCTION`
71+
and `@JacksonXmlElementWrapper` annotation fails
72+
(3.2.0)
73+
6974
Josip Antoliš (@Antolius)
7075
* Reported #517: XML wrapper doesn't work with java records
7176
(3.2.0)

release-notes/VERSION

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ Version: 3.x (for earlier see VERSION-2.x)
4848
`FromXmlParser.getRootElementName()`)
4949
(reported by Sam K)
5050
(fix by @cowtowncoder, w/ Claude code)
51+
#514: Deserialisation to polymorphic class using `JsonTypeInfo.Id.DEDUCTION`
52+
and `@JacksonXmlElementWrapper` annotation fails
53+
(reported by Alexios P)
54+
(fix by @cowtowncoder, w/ Claude code)
5155
#517: XML wrapper doesn't work with java records
5256
(reported by Josip A)
5357
(fix by Christopher M)

src/main/java/tools/jackson/dataformat/xml/deser/FromXmlParser.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ public JacksonFeatureSet<StreamReadCapability> streamReadCapabilities() {
261261
return XML_READ_CAPABILITIES;
262262
}
263263

264+
// @since 3.2
265+
@Override
266+
public boolean willInternPropertyNames() { return false; }
267+
264268
/*
265269
/**********************************************************************
266270
/* Extended API, access to some internal components
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package tools.jackson.dataformat.xml.lists;
2+
3+
import java.util.List;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
import com.fasterxml.jackson.annotation.*;
8+
9+
import tools.jackson.dataformat.xml.XmlMapper;
10+
import tools.jackson.dataformat.xml.XmlTestUtil;
11+
import tools.jackson.dataformat.xml.annotation.*;
12+
import static org.junit.jupiter.api.Assertions.*;
13+
14+
// [dataformat-xml#514]: Deserialisation to polymorphic class using
15+
// `JsonTypeInfo.Id.DEDUCTION` and `@JacksonXmlElementWrapper` fails
16+
public class DeductionWithUnwrappedList514Test extends XmlTestUtil
17+
{
18+
static class NestedClass {
19+
@JacksonXmlProperty(localName = "Text")
20+
public String text;
21+
}
22+
23+
@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION)
24+
@JsonSubTypes({
25+
@JsonSubTypes.Type(Success514.class),
26+
@JsonSubTypes.Type(Error514.class)
27+
})
28+
static abstract class Response514 { }
29+
30+
static class Success514 extends Response514 {
31+
@JacksonXmlProperty(localName = "SomeData")
32+
public String someData;
33+
34+
@JacksonXmlProperty(localName = "Detail")
35+
@JacksonXmlElementWrapper(useWrapping = false)
36+
public List<NestedClass> details;
37+
}
38+
39+
static class Error514 extends Response514 {
40+
@JacksonXmlProperty(localName = "ErrorCode")
41+
public String errorCode;
42+
}
43+
44+
@JsonRootName("RootTag")
45+
static class WholeResponse {
46+
@JacksonXmlProperty(localName = "Response")
47+
public Response514 response;
48+
}
49+
50+
// Direct deserialization without deduction — should work
51+
@JsonRootName("RootTag")
52+
static class WholeResponseDirect {
53+
@JacksonXmlProperty(localName = "Response")
54+
public Success514 response;
55+
}
56+
57+
private final XmlMapper MAPPER = newMapper();
58+
59+
@Test
60+
public void testDirectDeserializationWithoutDeduction() throws Exception
61+
{
62+
String xml =
63+
"<RootTag>"
64+
+ "<Response>"
65+
+ "<SomeData>hello</SomeData>"
66+
+ "<Detail><Text>hello world</Text></Detail>"
67+
+ "</Response>"
68+
+ "</RootTag>";
69+
WholeResponseDirect result = MAPPER.readValue(xml, WholeResponseDirect.class);
70+
assertNotNull(result);
71+
assertNotNull(result.response);
72+
assertEquals("hello", result.response.someData);
73+
assertNotNull(result.response.details);
74+
assertEquals(1, result.response.details.size());
75+
assertEquals("hello world", result.response.details.get(0).text);
76+
}
77+
78+
// [dataformat-xml#514]
79+
@Test
80+
public void testDeductionWithUnwrappedList() throws Exception
81+
{
82+
String xml =
83+
"<RootTag>"
84+
+ "<Response>"
85+
+ "<SomeData>hello</SomeData>"
86+
+ "<Detail><Text>hello world</Text></Detail>"
87+
+ "</Response>"
88+
+ "</RootTag>";
89+
WholeResponse result = MAPPER.readValue(xml, WholeResponse.class);
90+
assertNotNull(result);
91+
assertNotNull(result.response);
92+
assertInstanceOf(Success514.class, result.response);
93+
Success514 success = (Success514) result.response;
94+
assertEquals("hello", success.someData);
95+
assertNotNull(success.details);
96+
assertEquals(1, success.details.size());
97+
assertEquals("hello world", success.details.get(0).text);
98+
}
99+
}

0 commit comments

Comments
 (0)