Search in sources :

Example 91 with JsonFactory

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("|")));
}
Also used : DefaultPrettyPrinter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter) JsonFactory(com.fasterxml.jackson.core.json.JsonFactory)

Example 92 with JsonFactory

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());
}
Also used : MinimalPrettyPrinter(com.fasterxml.jackson.core.util.MinimalPrettyPrinter) JsonFactory(com.fasterxml.jackson.core.json.JsonFactory)

Example 93 with JsonFactory

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();
}
Also used : JsonFactory(com.fasterxml.jackson.core.json.JsonFactory)

Example 94 with JsonFactory

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);
    }
}
Also used : JsonFactory(com.fasterxml.jackson.core.json.JsonFactory)

Example 95 with JsonFactory

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);
    }
}
Also used : JsonFactory(com.fasterxml.jackson.core.json.JsonFactory)

Aggregations

JsonFactory (com.fasterxml.jackson.core.json.JsonFactory)137 AsyncReaderWrapper (com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)5 DefaultPrettyPrinter (com.fasterxml.jackson.core.util.DefaultPrettyPrinter)3 JsonParser (com.fasterxml.jackson.core.JsonParser)2 SerializedString (com.fasterxml.jackson.core.io.SerializedString)2 NonBlockingJsonParserBase (com.fasterxml.jackson.core.json.async.NonBlockingJsonParserBase)2 ByteQuadsCanonicalizer (com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer)2 MinimalPrettyPrinter (com.fasterxml.jackson.core.util.MinimalPrettyPrinter)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 BigDecimal (java.math.BigDecimal)2 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 StringWriter (java.io.StringWriter)1 Field (java.lang.reflect.Field)1 BigInteger (java.math.BigInteger)1 HashSet (java.util.HashSet)1