Search in sources :

Example 31 with JsonFactory

use of com.fasterxml.jackson.core.json.JsonFactory in project jackson-core by FasterXML.

the class TestPrettyPrinter method testSimpleDocWithMinimal.

@SuppressWarnings("resource")
public void testSimpleDocWithMinimal() throws Exception {
    StringWriter sw = new StringWriter();
    JsonGenerator gen = new JsonFactory().createGenerator(ObjectWriteContext.empty(), sw);
    // first with standard minimal
    gen.setPrettyPrinter(new MinimalPrettyPrinter());
    String docStr = _verifyPrettyPrinter(gen, sw);
    // which should have no linefeeds, tabs
    assertEquals(-1, docStr.indexOf('\n'));
    assertEquals(-1, docStr.indexOf('\t'));
    // And then with slightly customized variant
    gen = new JsonFactory().createGenerator(ObjectWriteContext.empty(), sw);
    gen.setPrettyPrinter(new MinimalPrettyPrinter() {

        @Override
        public // use TAB between array values
        void beforeArrayValues(JsonGenerator jg) throws IOException, JsonGenerationException {
            jg.writeRaw("\t");
        }
    });
    docStr = _verifyPrettyPrinter(gen, sw);
    assertEquals(-1, docStr.indexOf('\n'));
    assertTrue(docStr.indexOf('\t') >= 0);
    gen.close();
}
Also used : MinimalPrettyPrinter(com.fasterxml.jackson.core.util.MinimalPrettyPrinter) JsonFactory(com.fasterxml.jackson.core.json.JsonFactory)

Example 32 with JsonFactory

use of com.fasterxml.jackson.core.json.JsonFactory in project jackson-core by FasterXML.

the class TestPrettyPrinter method testCustomSeparatorsWithPP.

public void testCustomSeparatorsWithPP() throws Exception {
    StringWriter sw = new StringWriter();
    JsonGenerator gen = new JsonFactory().createGenerator(ObjectWriteContext.empty(), sw);
    gen.setPrettyPrinter(new DefaultPrettyPrinter().withSeparators(Separators.createDefaultInstance().withObjectFieldValueSeparator('=').withObjectEntrySeparator(';').withArrayValueSeparator('|')));
    _writeTestDocument(gen);
    gen.close();
    assertEquals("[ 3| \"abc\"| [ true ]| {" + DefaultIndenter.SYS_LF + "  \"f\" = null;" + DefaultIndenter.SYS_LF + "  \"f2\" = null" + DefaultIndenter.SYS_LF + "} ]", sw.toString());
}
Also used : DefaultPrettyPrinter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter) JsonFactory(com.fasterxml.jackson.core.json.JsonFactory)

Example 33 with JsonFactory

use of com.fasterxml.jackson.core.json.JsonFactory in project jackson-core by FasterXML.

the class CommentParsingTest method testDefaultSettings.

/*
    /**********************************************************
    /* Test method wrappers
    /**********************************************************
     */
/**
 * Unit test for verifying that by default comments are not
 * recognized.
 */
public void testDefaultSettings() throws Exception {
    JsonFactory f = new JsonFactory();
    assertFalse(f.isEnabled(JsonParser.Feature.ALLOW_COMMENTS));
    JsonParser p = f.createParser(ObjectReadContext.empty(), new StringReader("[ 1 ]"));
    assertFalse(p.isEnabled(JsonParser.Feature.ALLOW_COMMENTS));
    p.close();
}
Also used : JsonFactory(com.fasterxml.jackson.core.json.JsonFactory)

Example 34 with JsonFactory

use of com.fasterxml.jackson.core.json.JsonFactory in project jackson-core by FasterXML.

the class CommentParsingTest method testYAMLCommentsBytes.

public void testYAMLCommentsBytes() throws Exception {
    JsonFactory f = JsonFactory.builder().enable(JsonParser.Feature.ALLOW_YAML_COMMENTS).build();
    _testYAMLComments(f, MODE_INPUT_STREAM);
    _testCommentsBeforePropValue(f, MODE_INPUT_STREAM, "# foo\n");
    _testYAMLComments(f, MODE_INPUT_STREAM_THROTTLED);
    _testCommentsBeforePropValue(f, MODE_INPUT_STREAM_THROTTLED, "# foo\n");
    _testYAMLComments(f, MODE_DATA_INPUT);
    _testCommentsBeforePropValue(f, MODE_DATA_INPUT, "# foo\n");
}
Also used : JsonFactory(com.fasterxml.jackson.core.json.JsonFactory)

Example 35 with JsonFactory

use of com.fasterxml.jackson.core.json.JsonFactory in project jackson-core by FasterXML.

the class CommentParsingTest method testYAMLCommentsChars.

public void testYAMLCommentsChars() throws Exception {
    JsonFactory f = JsonFactory.builder().enable(JsonParser.Feature.ALLOW_YAML_COMMENTS).build();
    _testYAMLComments(f, MODE_READER);
    final String COMMENT = "# foo\n";
    _testCommentsBeforePropValue(f, MODE_READER, COMMENT);
    _testCommentsBetweenArrayValues(f, MODE_READER, COMMENT);
}
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