2
2
3
3
import java .beans .ConstructorProperties ;
4
4
5
+ import com .fasterxml .jackson .annotation .JsonCreator ;
5
6
import com .fasterxml .jackson .dataformat .xml .XmlMapper ;
6
7
import com .fasterxml .jackson .dataformat .xml .XmlTestBase ;
7
8
import com .fasterxml .jackson .dataformat .xml .annotation .JacksonXmlProperty ;
13
14
// special meaning so that annotation CANNOT specify it, either.
14
15
public class XmlTextViaCreator306Test extends XmlTestBase
15
16
{
17
+ // [dataformat-xml#306]
16
18
@ JacksonXmlRootElement (localName = "ROOT" )
17
19
static class Root {
18
20
@ JacksonXmlProperty (localName = "CHILD" )
@@ -64,6 +66,21 @@ static class ChildWithoutConstructor {
64
66
public String el ;
65
67
}
66
68
69
+ // [dataformat-xml#423]
70
+ static class Sample423
71
+ {
72
+ final String text ;
73
+ final String attribute ;
74
+
75
+ @ JsonCreator
76
+ public Sample423 (@ JacksonXmlText String text ,
77
+ @ JacksonXmlProperty (localName = "attribute" , isAttribute = true )
78
+ String attribute ) {
79
+ this .text = text ;
80
+ this .attribute = attribute ;
81
+ }
82
+ }
83
+
67
84
/*
68
85
/********************************************************
69
86
/* Test methods
@@ -72,6 +89,7 @@ static class ChildWithoutConstructor {
72
89
73
90
private final XmlMapper MAPPER = newMapper ();
74
91
92
+ // [dataformat-xml#306]
75
93
public void testIssue306WithCtor () throws Exception
76
94
{
77
95
final String XML = "<ROOT><CHILD attr='attr_value'>text</CHILD></ROOT>" ;
@@ -85,4 +103,13 @@ public void testIssue306NoCtor() throws Exception
85
103
RootWithoutConstructor rootNoCtor = MAPPER .readValue (XML , RootWithoutConstructor .class );
86
104
assertNotNull (rootNoCtor );
87
105
}
106
+
107
+ // [dataformat-xml#423]
108
+ public void testXmlTextViaCtor423 () throws Exception
109
+ {
110
+ final String XML = "<Sample423 attribute='attrValue'>text value</Sample423>" ;
111
+ Sample423 result = MAPPER .readValue (XML , Sample423 .class );
112
+ assertEquals ("attrValue" , result .attribute );
113
+ assertEquals ("text value" , result .text );
114
+ }
88
115
}
0 commit comments