Skip to content

Commit c7a2478

Browse files
committed
...
1 parent 6ab836e commit c7a2478

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/test/java/com/fasterxml/jackson/dataformat/xml/misc/RootNameTest.java

+12-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.List;
77

88
import com.fasterxml.jackson.databind.ObjectWriter;
9+
import com.fasterxml.jackson.databind.PropertyName;
910
import com.fasterxml.jackson.dataformat.xml.*;
1011
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
1112

@@ -79,27 +80,34 @@ public void testDynamicRootName() throws IOException
7980
{
8081
String xml;
8182

82-
ObjectWriter w = _xmlMapper.writer().withRootName("rudy");
83+
ObjectWriter w = _xmlMapper.writer().withRootName(PropertyName.construct("rudy", "localhost"));
8384

8485
xml = w.writeValueAsString(new StringBean("foo"));
85-
assertEquals("<rudy><text>foo</text></rudy>", xml);
86+
assertEquals("<rudy xmlns=\"localhost\"><text xmlns=\"\">foo</text></rudy>", xml);
8687

8788
xml = w.writeValueAsString(new StringBean(null));
88-
assertEquals("<rudy><text/></rudy>", xml);
89+
assertEquals("<rudy xmlns=\"localhost\"><text xmlns=\"\"/></rudy>", xml);
8990

9091
// and even with null will respect configured root name
9192
xml = w.writeValueAsString(null);
92-
assertEquals("<rudy/>", xml);
93+
assertEquals("<rudy xmlns=\"localhost\"/>", xml);
9394
}
9495

9596
public void testDynamicRootNameForList() throws IOException
9697
{
9798
String xml;
9899

100+
// First: using explicit root name override, simple String
99101
xml = _xmlMapper.writer().withRootName("Listy")
100102
.writeValueAsString(Arrays.asList("abc", "def"));
101103
assertEquals("<Listy><item>abc</item><item>def</item></Listy>", xml);
102104

105+
// Second: using explicit root name override, with namespace
106+
xml = _xmlMapper.writer().withRootName(PropertyName.construct("Spaced", "http://foo"))
107+
.writeValueAsString(Arrays.asList("foo", "bar"));
108+
assertEquals("<Spaced xmlns=\"http://foo\"><item>foo</item><item>bar</item></Spaced>", xml);
109+
110+
// Third: root name annotation
103111
xml = _xmlMapper.writer()
104112
.writeValueAsString(new StringList("a", "b"));
105113
assertEquals("<TheStrings><item>a</item><item>b</item></TheStrings>", xml);

0 commit comments

Comments
 (0)