Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@ public boolean inRoot() {
return _streamWriteContext.inRoot();
}

@Override // @since 3.0
public XmlPrettyPrinter getPrettyPrinter() {
return _xmlPrettyPrinter;
}

/*
/**********************************************************************
/* Extended API, access to some internal components
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package tools.jackson.dataformat.xml.ser;

import java.io.StringWriter;
import java.util.*;

import javax.xml.namespace.QName;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

import tools.jackson.databind.SerializationFeature;
import tools.jackson.core.JsonGenerator;

import tools.jackson.databind.SerializationFeature;
import tools.jackson.dataformat.xml.XmlMapper;
import tools.jackson.dataformat.xml.XmlTestUtil;
import tools.jackson.dataformat.xml.XmlWriteFeature;
Expand Down Expand Up @@ -147,7 +151,7 @@ public void testSimpleIntBean() throws Exception
@Test
public void testSimpleMap() throws Exception
{
Map<String,String> map = new HashMap<String,String>();
Map<String,String> map = new HashMap<>();
map.put("a", "b");
String xml = _xmlMapper.writeValueAsString(map);

Expand Down Expand Up @@ -285,4 +289,31 @@ public void testNewLine_UseSystemDefaultLineSeperatorOnNullCustomNewLine() throw
+ "</Company>" + DEFAULT_NEW_LINE,
xml);
}

// [core#1480]
@Test
void accessToPrettyPrinter() {
// By default, no indenting:
XmlMapper noIndentMapper = newMapper();
try (JsonGenerator g = noIndentMapper.createGenerator(new StringWriter())) {
assertNull(g.getPrettyPrinter());
_writeDoc(g);
}

// But can enable
XmlMapper indentingMapper = mapperBuilder()
.enable(SerializationFeature.INDENT_OUTPUT)
.build();
try (JsonGenerator g = indentingMapper.createGenerator(new StringWriter())) {
assertTrue(g.getPrettyPrinter() instanceof DefaultXmlPrettyPrinter);
_writeDoc(g);
}
}

private void _writeDoc(JsonGenerator g) {
((ToXmlGenerator) g).setNextName(new QName("abc"));
g.writeStartObject();
g.writeNumberProperty("value", 42);
g.writeEndObject();
}
}