@@ -14,18 +14,19 @@ public class TestDOM extends com.fasterxml.jackson.databind.BaseMapTest
14
14
"<root attr='3'><leaf>Rock & Roll!</leaf><?proc instr?></root>" ;
15
15
final static String SIMPLE_XML_NS =
16
16
"<root ns:attr='abc' xmlns:ns='http://foo' />" ;
17
+
18
+ private final ObjectMapper MAPPER = new ObjectMapper ();
17
19
18
20
public void testSerializeSimpleNonNS () throws Exception
19
21
{
20
22
// Let's just parse first, easiest
21
23
Document doc = DocumentBuilderFactory .newInstance ().newDocumentBuilder ().parse
22
24
(new InputSource (new StringReader (SIMPLE_XML )));
23
25
assertNotNull (doc );
24
- ObjectMapper mapper = new ObjectMapper ();
25
26
// need to strip xml declaration, if any
26
- String outputRaw = mapper .writeValueAsString (doc );
27
+ String outputRaw = MAPPER .writeValueAsString (doc );
27
28
// And re-parse as String, since JSON has quotes...
28
- String output = mapper .readValue (outputRaw , String .class );
29
+ String output = MAPPER .readValue (outputRaw , String .class );
29
30
/* ... and finally, normalize to (close to) canonical XML
30
31
* output (single vs double quotes, xml declaration etc)
31
32
*/
@@ -34,16 +35,15 @@ public void testSerializeSimpleNonNS() throws Exception
34
35
35
36
public void testDeserializeNonNS () throws Exception
36
37
{
37
- ObjectMapper mapper = new ObjectMapper ();
38
38
for (int i = 0 ; i < 2 ; ++i ) {
39
39
Document doc ;
40
40
41
41
if (i == 0 ) {
42
42
// First, as Document:
43
- doc = mapper .readValue (quote (SIMPLE_XML ), Document .class );
43
+ doc = MAPPER .readValue (quote (SIMPLE_XML ), Document .class );
44
44
} else {
45
45
// and then as plain Node (no difference)
46
- Node node = mapper .readValue (quote (SIMPLE_XML ), Node .class );
46
+ Node node = MAPPER .readValue (quote (SIMPLE_XML ), Node .class );
47
47
doc = (Document ) node ;
48
48
}
49
49
Element root = doc .getDocumentElement ();
@@ -66,8 +66,7 @@ public void testDeserializeNonNS() throws Exception
66
66
67
67
public void testDeserializeNS () throws Exception
68
68
{
69
- ObjectMapper mapper = new ObjectMapper ();
70
- Document doc = mapper .readValue (quote (SIMPLE_XML_NS ), Document .class );
69
+ Document doc = MAPPER .readValue (quote (SIMPLE_XML_NS ), Document .class );
71
70
Element root = doc .getDocumentElement ();
72
71
assertNotNull (root );
73
72
assertEquals ("root" , root .getTagName ());
@@ -82,9 +81,9 @@ public void testDeserializeNS() throws Exception
82
81
}
83
82
84
83
/*
85
- **********************************************************
86
- * Helper methods
87
- **********************************************************
84
+ / **********************************************************
85
+ / * Helper methods
86
+ / **********************************************************
88
87
*/
89
88
90
89
protected static String normalizeOutput (String output )
0 commit comments