Search in sources :

Example 71 with JsonFactory

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

the class AsyncNonStdParsingTest method testLargeUnquotedNames.

public void testLargeUnquotedNames() throws Exception {
    JsonFactory f = JsonFactory.builder().enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES).build();
    StringBuilder sb = new StringBuilder(5000);
    sb.append("[\n");
    final int REPS = 1050;
    for (int i = 0; i < REPS; ++i) {
        if (i > 0) {
            sb.append(',');
            if ((i & 7) == 0) {
                sb.append('\n');
            }
        }
        sb.append("{");
        sb.append("abc").append(i & 127).append(':');
        sb.append((i & 1) != 0);
        sb.append("}\n");
    }
    sb.append("]");
    String doc = sb.toString();
    _testLargeUnquoted(f, REPS, doc, 0, 99);
    _testLargeUnquoted(f, REPS, doc, 0, 5);
    _testLargeUnquoted(f, REPS, doc, 0, 3);
    _testLargeUnquoted(f, REPS, doc, 0, 2);
    _testLargeUnquoted(f, REPS, doc, 0, 1);
    _testLargeUnquoted(f, REPS, doc, 1, 99);
    _testLargeUnquoted(f, REPS, doc, 1, 1);
}
Also used : JsonFactory(com.fasterxml.jackson.core.json.JsonFactory)

Example 72 with JsonFactory

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

the class AsyncNonStdParsingTest method testSimpleUnquotedNames.

public void testSimpleUnquotedNames() throws Exception {
    JsonFactory f = JsonFactory.builder().enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES).build();
    _testSimpleUnquoted(f, 0, 99);
    _testSimpleUnquoted(f, 0, 5);
    _testSimpleUnquoted(f, 0, 3);
    _testSimpleUnquoted(f, 0, 2);
    _testSimpleUnquoted(f, 0, 1);
    _testSimpleUnquoted(f, 1, 99);
    _testSimpleUnquoted(f, 1, 3);
    _testSimpleUnquoted(f, 1, 1);
}
Also used : JsonFactory(com.fasterxml.jackson.core.json.JsonFactory)

Example 73 with JsonFactory

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

the class AsyncNonStdParsingTest method testAposQuotingDisabled.

/**
 * Test to verify that the default parser settings do not
 * accept single-quotes for String values (field names,
 * textual values)
 */
public void testAposQuotingDisabled() throws Exception {
    JsonFactory f = new JsonFactory();
    _testSingleQuotesDefault(f, 0, 99);
    _testSingleQuotesDefault(f, 0, 5);
    _testSingleQuotesDefault(f, 0, 3);
    _testSingleQuotesDefault(f, 0, 1);
    _testSingleQuotesDefault(f, 1, 99);
    _testSingleQuotesDefault(f, 1, 1);
}
Also used : JsonFactory(com.fasterxml.jackson.core.json.JsonFactory)

Example 74 with JsonFactory

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

the class AsyncCommentParsingTest method testCCommentsEnabled.

public void testCCommentsEnabled() throws Exception {
    JsonFactory f = JsonFactory.builder().enable(JsonParser.Feature.ALLOW_COMMENTS).build();
    final String COMMENT = "/* foo */\n";
    _testCommentsBeforePropValue(f, COMMENT, 99);
    _testCommentsBeforePropValue(f, COMMENT, 3);
    _testCommentsBeforePropValue(f, COMMENT, 1);
}
Also used : JsonFactory(com.fasterxml.jackson.core.json.JsonFactory)

Example 75 with JsonFactory

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

the class Base64BinaryParsingTest method _testStreaming.

private void _testStreaming(int mode) throws IOException {
    final int[] SIZES = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 12, 100, 350, 1900, 6000, 19000, 65000, 139000 };
    JsonFactory jsonFactory = new JsonFactory();
    final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    StringWriter chars = null;
    for (int size : SIZES) {
        byte[] data = _generateData(size);
        JsonGenerator g;
        if (mode == MODE_READER) {
            chars = new StringWriter();
            g = jsonFactory.createGenerator(ObjectWriteContext.empty(), chars);
        } else {
            bytes.reset();
            g = jsonFactory.createGenerator(ObjectWriteContext.empty(), bytes, JsonEncoding.UTF8);
        }
        g.writeStartObject();
        g.writeFieldName("b");
        g.writeBinary(data);
        g.writeEndObject();
        g.close();
        // and verify
        JsonParser p;
        if (mode == MODE_READER) {
            p = jsonFactory.createParser(ObjectReadContext.empty(), chars.toString());
        } else {
            p = createParser(jsonFactory, mode, bytes.toByteArray());
        }
        assertToken(JsonToken.START_OBJECT, p.nextToken());
        assertToken(JsonToken.FIELD_NAME, p.nextToken());
        assertEquals("b", p.currentName());
        assertToken(JsonToken.VALUE_STRING, p.nextToken());
        ByteArrayOutputStream result = new ByteArrayOutputStream(size);
        int gotten = p.readBinaryValue(result);
        assertEquals(size, gotten);
        assertArrayEquals(data, result.toByteArray());
        assertToken(JsonToken.END_OBJECT, p.nextToken());
        if (mode != MODE_DATA_INPUT) {
            // no look-ahead for DataInput
            assertNull(p.nextToken());
        }
        p.close();
    }
}
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