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 @@ -482,9 +482,9 @@ private JsonParser _createParser(ObjectReadContext readCtxt, IOContext ioCtxt,
protected IonGenerator _createGenerator(ObjectWriteContext writeCtxt,
OutputStream out, JsonEncoding enc, boolean isManaged)
{
IonWriter ion;
IOContext ioCtxt = _createContext(_createContentReference(out), isManaged);
Closeable dst; // not necessarily same as 'out'...
final IonWriter ion;
final Closeable dst; // not necessarily same as 'out'...

// Binary writers are simpler: no alternate encodings
if (_cfgBinaryWriters) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,46 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;

// For [dataformats-binary#245]: no pretty-printing for textual format
public class PrettyPrintWriteTest
public class IonPrettyPrintWriteTest
{
@JsonPropertyOrder({ "x", "y" })
static class Point {
public int x = 1;
public int y = 2;
}

private final IonObjectMapper TEXTUAL_MAPPER = IonObjectMapper.builder(IonFactory.forTextualWriters()).build();

@Test
public void testBasicPrettyPrintTextual() throws Exception
public void prettyPrintTextual() throws Exception
{
final String EXP = "{\n x:1,\n y:2\n}";

IonObjectMapper mapper = IonObjectMapper.builder(IonFactory.forTextualWriters()).build();
String ion = mapper.writerWithDefaultPrettyPrinter()
String ion = TEXTUAL_MAPPER.writerWithDefaultPrettyPrinter()
.writeValueAsString(new Point());
assertEquals(EXP, ion.trim());

ion = mapper.writer()
ion = TEXTUAL_MAPPER.writer()
.with(SerializationFeature.INDENT_OUTPUT)
.writeValueAsString(new Point());
assertEquals(EXP, ion.trim());

IonObjectMapper mapper = TEXTUAL_MAPPER.rebuild()
.enable(SerializationFeature.INDENT_OUTPUT)
.build();
ion = mapper.writeValueAsString(new Point());
assertEquals(EXP, ion.trim());

// But also no indentation if not requested
ion = mapper.writer()
.without(SerializationFeature.INDENT_OUTPUT)
.writeValueAsString(new Point());
assertEquals("{x:1,y:2}", ion.trim());
}

// and with binary format, should simply be no-op
@Test
public void testIgnorePrettyPrintForBinary() throws Exception
public void prettyPrintIgnoredForBinary() throws Exception
{
IonObjectMapper mapper = IonObjectMapper.builder(IonFactory.forBinaryWriters()).build();
byte[] encoded = mapper.writerWithDefaultPrettyPrinter().writeValueAsBytes(new Point());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ public static IOContext testIOContext() {
protected JsonParser createParserUsingStream(TokenStreamFactory f, byte[] input)
throws IOException
{
return f.createParser(new ByteArrayInputStream(input));
return f.createParser(ObjectReadContext.empty(),
new ByteArrayInputStream(input));
}

/*
Expand Down
Loading