8
8
import com .fasterxml .jackson .databind .node .ObjectNode ;
9
9
import com .fasterxml .jackson .dataformat .xml .XmlTestBase ;
10
10
11
- // for [dataformat-xml#205], handling "untyped" ({@code java.lang.Object}-targeted)
12
- // deserialization, including handling of element sequences
13
- public class UntypedObjectDeser205Test extends XmlTestBase
11
+ public class UntypedObjectDeserTest extends XmlTestBase
14
12
{
15
13
private final ObjectMapper XML_MAPPER = newMapper ();
16
14
17
- private final ObjectMapper JSON_MAPPER = new JsonMapper ();
18
-
15
+ // for [dataformat-xml#205], handling "untyped" ({@code java.lang.Object}-targeted)
16
+ // deserialization, including handling of element sequences
19
17
public void testRepeatingElements () throws Exception
20
18
{
21
19
final String XML =
@@ -39,8 +37,8 @@ public void testRepeatingElements() throws Exception
39
37
" </dog>\n " +
40
38
" </dogs>\n " +
41
39
"</person>" ;
42
- final JsonNode fromXml = JSON_MAPPER .valueToTree (XML_MAPPER .readValue (XML , Object .class ));
43
- final ObjectNode exp = JSON_MAPPER .createObjectNode ();
40
+ final JsonNode fromXml = XML_MAPPER .valueToTree (XML_MAPPER .readValue (XML , Object .class ));
41
+ final ObjectNode exp = XML_MAPPER .createObjectNode ();
44
42
exp .put ("name" , "John" );
45
43
{
46
44
exp .putArray ("parent" )
@@ -60,7 +58,26 @@ public void testRepeatingElements() throws Exception
60
58
.put ("age" , "14" );
61
59
}
62
60
if (!fromXml .equals (exp )) {
63
- ObjectWriter w = JSON_MAPPER .writerWithDefaultPrettyPrinter ();
61
+ ObjectWriter w = new JsonMapper ().writerWithDefaultPrettyPrinter ();
62
+ fail ("Expected:\n " +w .writeValueAsString (exp )+"\n got:\n " +w .writeValueAsString (fromXml ));
63
+ }
64
+ }
65
+
66
+ // [dataformat-xml#405]: support mixed content
67
+ public void testMixedContent () throws Exception
68
+ {
69
+ final String XML = "<root>first<a>123</a>second<b>abc</b>last</root>" ;
70
+ final JsonNode fromXml = XML_MAPPER .valueToTree (XML_MAPPER .readValue (XML , Object .class ));
71
+ final ObjectNode exp = XML_MAPPER .createObjectNode ();
72
+ exp .putArray ("" )
73
+ .add ("first" )
74
+ .add ("second" )
75
+ .add ("last" );
76
+ exp .put ("a" , "123" );
77
+ exp .put ("b" , "abc" );
78
+
79
+ if (!fromXml .equals (exp )) {
80
+ ObjectWriter w = new JsonMapper ().writerWithDefaultPrettyPrinter ();
64
81
fail ("Expected:\n " +w .writeValueAsString (exp )+"\n got:\n " +w .writeValueAsString (fromXml ));
65
82
}
66
83
}
0 commit comments