use of com.fasterxml.jackson.core.json.JsonFactory in project jackson-core by FasterXML.
the class TestPrettyPrinter method testCustomRootSeparatorWithPP.
// [Issue#26]
public void testCustomRootSeparatorWithPP() throws Exception {
JsonFactory f = new JsonFactory();
// first, no pretty-printing (will still separate root values with a space!)
assertEquals("{} {} []", _generateRoot(f, null));
// First with default pretty printer, default configs:
assertEquals("{ } { } [ ]", _generateRoot(f, new DefaultPrettyPrinter()));
// then custom:
assertEquals("{ }|{ }|[ ]", _generateRoot(f, new DefaultPrettyPrinter("|")));
}
use of com.fasterxml.jackson.core.json.JsonFactory in project jackson-core by FasterXML.
the class TestPrettyPrinter method testCustomSeparatorsWithMinimal.
public void testCustomSeparatorsWithMinimal() throws Exception {
StringWriter sw = new StringWriter();
JsonGenerator gen = new JsonFactory().createGenerator(ObjectWriteContext.empty(), sw);
gen.setPrettyPrinter(new MinimalPrettyPrinter().setSeparators(Separators.createDefaultInstance().withObjectFieldValueSeparator('=').withObjectEntrySeparator(';').withArrayValueSeparator('|')));
_writeTestDocument(gen);
gen.close();
assertEquals("[3|\"abc\"|[true]|{\"f\"=null;\"f2\"=null}]", sw.toString());
}
use of com.fasterxml.jackson.core.json.JsonFactory in project jackson-core by FasterXML.
the class TestPrettyPrinter method _generateRoot.
protected String _generateRoot(TokenStreamFactory f, PrettyPrinter pp) throws IOException {
StringWriter sw = new StringWriter();
JsonGenerator gen = new JsonFactory().createGenerator(ObjectWriteContext.empty(), sw);
gen.setPrettyPrinter(pp);
gen.writeStartObject();
gen.writeEndObject();
gen.writeStartObject();
gen.writeEndObject();
gen.writeStartArray();
gen.writeEndArray();
gen.close();
return sw.toString();
}
use of com.fasterxml.jackson.core.json.JsonFactory in project jackson-core by FasterXML.
the class TestPrettyPrinter method testArrayCount.
public void testArrayCount() throws Exception {
final String EXP = "[6,[1,2,9(3)](2)]";
final JsonFactory f = new JsonFactory();
for (int i = 0; i < 2; ++i) {
boolean useBytes = (i > 0);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
StringWriter sw = new StringWriter();
JsonGenerator gen = useBytes ? f.createGenerator(ObjectWriteContext.empty(), bytes) : f.createGenerator(ObjectWriteContext.empty(), sw);
gen.setPrettyPrinter(new CountPrinter());
gen.writeStartArray();
gen.writeNumber(6);
gen.writeStartArray();
gen.writeNumber(1);
gen.writeNumber(2);
gen.writeNumber(9);
gen.writeEndArray();
gen.writeEndArray();
gen.close();
String json = useBytes ? bytes.toString("UTF-8") : sw.toString();
assertEquals(EXP, json);
}
}
use of com.fasterxml.jackson.core.json.JsonFactory in project jackson-core by FasterXML.
the class TestPrettyPrinter method testObjectCount.
/*
/**********************************************************
/* Test methods
/**********************************************************
*/
public void testObjectCount() throws Exception {
final String EXP = "{\"x\":{\"a\":1,\"b\":2(2)}(1)}";
final JsonFactory f = new JsonFactory();
for (int i = 0; i < 2; ++i) {
boolean useBytes = (i > 0);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
StringWriter sw = new StringWriter();
JsonGenerator gen = useBytes ? f.createGenerator(ObjectWriteContext.empty(), bytes) : f.createGenerator(ObjectWriteContext.empty(), sw);
gen.setPrettyPrinter(new CountPrinter());
gen.writeStartObject();
gen.writeFieldName("x");
gen.writeStartObject();
gen.writeNumberField("a", 1);
gen.writeNumberField("b", 2);
gen.writeEndObject();
gen.writeEndObject();
gen.close();
String json = useBytes ? bytes.toString("UTF-8") : sw.toString();
assertEquals(EXP, json);
}
}
Aggregations