|
1 | 1 | package tools.jackson.dataformat.xml.ser;
|
2 | 2 |
|
| 3 | +import java.io.StringWriter; |
3 | 4 | import java.util.*;
|
4 | 5 |
|
| 6 | +import javax.xml.namespace.QName; |
| 7 | + |
5 | 8 | import org.junit.jupiter.api.BeforeEach;
|
6 | 9 | import org.junit.jupiter.api.Test;
|
7 | 10 |
|
8 | 11 | import com.fasterxml.jackson.annotation.JsonInclude;
|
9 | 12 | import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
10 | 13 |
|
11 |
| -import tools.jackson.databind.SerializationFeature; |
| 14 | +import tools.jackson.core.JsonGenerator; |
12 | 15 |
|
| 16 | +import tools.jackson.databind.SerializationFeature; |
13 | 17 | import tools.jackson.dataformat.xml.XmlMapper;
|
14 | 18 | import tools.jackson.dataformat.xml.XmlTestUtil;
|
15 | 19 | import tools.jackson.dataformat.xml.XmlWriteFeature;
|
@@ -147,7 +151,7 @@ public void testSimpleIntBean() throws Exception
|
147 | 151 | @Test
|
148 | 152 | public void testSimpleMap() throws Exception
|
149 | 153 | {
|
150 |
| - Map<String,String> map = new HashMap<String,String>(); |
| 154 | + Map<String,String> map = new HashMap<>(); |
151 | 155 | map.put("a", "b");
|
152 | 156 | String xml = _xmlMapper.writeValueAsString(map);
|
153 | 157 |
|
@@ -285,4 +289,31 @@ public void testNewLine_UseSystemDefaultLineSeperatorOnNullCustomNewLine() throw
|
285 | 289 | + "</Company>" + DEFAULT_NEW_LINE,
|
286 | 290 | xml);
|
287 | 291 | }
|
| 292 | + |
| 293 | + // [core#1480] |
| 294 | + @Test |
| 295 | + void accessToPrettyPrinter() { |
| 296 | + // By default, no indenting: |
| 297 | + XmlMapper noIndentMapper = newMapper(); |
| 298 | + try (JsonGenerator g = noIndentMapper.createGenerator(new StringWriter())) { |
| 299 | + assertNull(g.getPrettyPrinter()); |
| 300 | + _writeDoc(g); |
| 301 | + } |
| 302 | + |
| 303 | + // But can enable |
| 304 | + XmlMapper indentingMapper = mapperBuilder() |
| 305 | + .enable(SerializationFeature.INDENT_OUTPUT) |
| 306 | + .build(); |
| 307 | + try (JsonGenerator g = indentingMapper.createGenerator(new StringWriter())) { |
| 308 | + assertTrue(g.getPrettyPrinter() instanceof DefaultXmlPrettyPrinter); |
| 309 | + _writeDoc(g); |
| 310 | + } |
| 311 | + } |
| 312 | + |
| 313 | + private void _writeDoc(JsonGenerator g) { |
| 314 | + ((ToXmlGenerator) g).setNextName(new QName("abc")); |
| 315 | + g.writeStartObject(); |
| 316 | + g.writeNumberProperty("value", 42); |
| 317 | + g.writeEndObject(); |
| 318 | + } |
288 | 319 | }
|
0 commit comments