1- package tools .jackson .dataformat .xml .tofix ;
1+ package tools .jackson .dataformat .xml .deser ;
22
33import org .junit .jupiter .api .Test ;
44
55import tools .jackson .databind .ObjectMapper ;
66import tools .jackson .dataformat .xml .XmlTestUtil ;
77import tools .jackson .dataformat .xml .annotation .JacksonXmlProperty ;
88import tools .jackson .dataformat .xml .annotation .JacksonXmlText ;
9- import tools .jackson .dataformat .xml .testutil .failure .JacksonTestFailureExpected ;
109
1110import static org .junit .jupiter .api .Assertions .assertEquals ;
1211import static org .junit .jupiter .api .Assertions .assertNotNull ;
@@ -39,6 +38,18 @@ static class Plain608 {
3938 public String text ;
4039 }
4140
41+ // Has @JacksonXmlText with mix of attributes and element properties
42+ static class Mixed608 {
43+ @ JacksonXmlProperty (isAttribute = true )
44+ public String attr ;
45+
46+ @ JacksonXmlProperty (isAttribute = false )
47+ public String elem ;
48+
49+ @ JacksonXmlText
50+ public String text ;
51+ }
52+
4253 private final ObjectMapper MAPPER = newMapper ();
4354
4455 // Works: nested has both a child element and text content
@@ -62,10 +73,8 @@ public void testPlainTextOnly608() throws Exception {
6273 assertEquals ("The text node." , result .plain .text );
6374 }
6475
65- // Fails: nested type has @JacksonXmlText plus other element properties,
66- // but XML only contains text (no child elements). Jackson incorrectly
67- // tries String-argument constructor instead of object deserialization.
68- @ JacksonTestFailureExpected
76+ // [dataformat-xml#608]: nested type has @JacksonXmlText plus other element
77+ // properties, but XML only contains text (no child elements).
6978 @ Test
7079 public void testNestedWithOnlyText608 () throws Exception {
7180 String xml = "<Root608><nested>The text node.</nested></Root608>" ;
@@ -75,4 +84,26 @@ public void testNestedWithOnlyText608() throws Exception {
7584 assertNull (result .nested .reallyNotHere );
7685 assertEquals ("The text node." , result .nested .text );
7786 }
87+
88+ // [dataformat-xml#608]: mixed attributes + elements + text, text-only XML
89+ @ Test
90+ public void testMixedTextOnly608 () throws Exception {
91+ String xml = "<Mixed608>The text node.</Mixed608>" ;
92+ Mixed608 result = MAPPER .readValue (xml , Mixed608 .class );
93+ assertNotNull (result );
94+ assertNull (result .attr );
95+ assertNull (result .elem );
96+ assertEquals ("The text node." , result .text );
97+ }
98+
99+ // [dataformat-xml#608]: mixed attributes + elements + text, with attribute present
100+ @ Test
101+ public void testMixedWithAttrAndText608 () throws Exception {
102+ String xml = "<Mixed608 attr=\" v\" >The text node.</Mixed608>" ;
103+ Mixed608 result = MAPPER .readValue (xml , Mixed608 .class );
104+ assertNotNull (result );
105+ assertEquals ("v" , result .attr );
106+ assertNull (result .elem );
107+ assertEquals ("The text node." , result .text );
108+ }
78109}
0 commit comments