Search in sources :

Example 16 with JsonFactory

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

the class TestByteBasedSymbols method testIssue207.

// as per name, for [core#207]
public void testIssue207() throws Exception {
    ByteQuadsCanonicalizer nc = ByteQuadsCanonicalizer.createRoot(-523743345);
    Field byteSymbolCanonicalizerField = JsonFactory.class.getDeclaredField("_byteSymbolCanonicalizer");
    byteSymbolCanonicalizerField.setAccessible(true);
    JsonFactory jsonF = new JsonFactory();
    byteSymbolCanonicalizerField.set(jsonF, nc);
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append("{\n");
    stringBuilder.append("    \"expectedGCperPosition\": null");
    for (int i = 0; i < 60; ++i) {
        stringBuilder.append(",\n    \"").append(i + 1).append("\": null");
    }
    stringBuilder.append("\n}");
    JsonParser p = jsonF.createParser(ObjectReadContext.empty(), stringBuilder.toString().getBytes("UTF-8"));
    while (p.nextToken() != null) {
    }
    p.close();
}
Also used : Field(java.lang.reflect.Field) JsonFactory(com.fasterxml.jackson.core.json.JsonFactory)

Example 17 with JsonFactory

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

the class TestSymbolTables method testShortNameCollisionsViaParser.

// [core#191]: similarly, but for "short" symbols:
public void testShortNameCollisionsViaParser() throws Exception {
    JsonFactory f = new JsonFactory();
    String json = _shortDoc191();
    JsonParser p;
    // First: ensure that char-based is fine
    p = f.createParser(ObjectReadContext.empty(), json);
    while (p.nextToken() != null) {
    }
    p.close();
    // and then that byte-based
    p = f.createParser(ObjectReadContext.empty(), json.getBytes("UTF-8"));
    while (p.nextToken() != null) {
    }
    p.close();
}
Also used : JsonFactory(com.fasterxml.jackson.core.json.JsonFactory)

Example 18 with JsonFactory

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

the class AsyncNonStdNumbersTest method testAllowInf.

public void testAllowInf() throws Exception {
    JsonFactory f = JsonFactory.builder().enable(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS).build();
    String JSON = "[ Infinity, +Infinity, -Infinity ]";
    _testAllowInf(f, JSON, 99);
    _testAllowInf(f, JSON, 5);
    _testAllowInf(f, JSON, 3);
    _testAllowInf(f, JSON, 2);
    _testAllowInf(f, JSON, 1);
    JSON = "[Infinity,+Infinity,-Infinity]";
    _testAllowInf(f, JSON, 99);
    _testAllowInf(f, JSON, 1);
    JSON = "[Infinity  ,   +Infinity   ,   -Infinity]";
    _testAllowInf(f, JSON, 99);
    _testAllowInf(f, JSON, 1);
}
Also used : JsonFactory(com.fasterxml.jackson.core.json.JsonFactory)

Example 19 with JsonFactory

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

the class AsyncParserNamesTest method testSymbolTableWithIntern.

public void testSymbolTableWithIntern() throws IOException {
    JsonFactory internF = JsonFactory.builder().enable(TokenStreamFactory.Feature.INTERN_FIELD_NAMES).build();
    final String STR1 = "a";
    byte[] doc = _jsonDoc("{ " + quote(STR1) + ":1, \"foobar\":2, \"longername\":3 }");
    AsyncReaderWrapper p = asyncForBytes(internF, 5, doc, 0);
    final ByteQuadsCanonicalizer symbols1 = ((NonBlockingJsonParserBase) p.parser()).symbolTableForTests();
    assertEquals(0, symbols1.size());
    assertEquals(JsonToken.START_OBJECT, p.nextToken());
    assertEquals(JsonToken.FIELD_NAME, p.nextToken());
    assertSame(STR1, p.currentName());
    assertEquals(1, symbols1.size());
    assertEquals(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertEquals(JsonToken.FIELD_NAME, p.nextToken());
    assertSame("foobar", p.currentName());
    assertEquals(2, symbols1.size());
    assertEquals(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertEquals(JsonToken.FIELD_NAME, p.nextToken());
    assertSame("longername", p.currentName());
    assertEquals(3, symbols1.size());
    assertEquals(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertEquals(JsonToken.END_OBJECT, p.nextToken());
    assertNull(p.nextToken());
    assertEquals(3, symbols1.size());
    p.close();
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) JsonFactory(com.fasterxml.jackson.core.json.JsonFactory) ByteQuadsCanonicalizer(com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer) NonBlockingJsonParserBase(com.fasterxml.jackson.core.json.async.NonBlockingJsonParserBase)

Example 20 with JsonFactory

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

the class AsyncRootValuesTest method _testTokenRootTokens.

private void _testTokenRootTokens(JsonToken expToken, String doc) throws Exception {
    byte[] input = _jsonDoc(doc);
    JsonFactory f = JSON_F;
    _testTokenRootTokens(expToken, f, input, 0, 90);
    _testTokenRootTokens(expToken, f, input, 0, 3);
    _testTokenRootTokens(expToken, f, input, 0, 2);
    _testTokenRootTokens(expToken, f, input, 0, 1);
    _testTokenRootTokens(expToken, f, input, 1, 90);
    _testTokenRootTokens(expToken, f, input, 1, 3);
    _testTokenRootTokens(expToken, f, input, 1, 1);
}
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