Search in sources :

Example 1 with NonBlockingJsonParserBase

use of com.fasterxml.jackson.core.json.async.NonBlockingJsonParserBase 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 2 with NonBlockingJsonParserBase

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

the class AsyncParserNamesTest method testSymbolTable.

public void testSymbolTable() throws IOException {
    final String STR1 = "a";
    byte[] doc = _jsonDoc("{ " + quote(STR1) + ":1, \"foobar\":2, \"longername\":3 }");
    JsonFactory f = JSON_F;
    AsyncReaderWrapper p = asyncForBytes(f, 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());
    // field names not intern()ed by default any more in 3.x
    assertEquals(STR1, p.currentName());
    // assertSame(STR1, p.currentName());
    assertEquals(1, symbols1.size());
    assertEquals(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertEquals(JsonToken.FIELD_NAME, p.nextToken());
    assertEquals("foobar", p.currentName());
    assertEquals(2, symbols1.size());
    assertEquals(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertEquals(JsonToken.FIELD_NAME, p.nextToken());
    assertEquals("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();
    // but let's verify that symbol table gets reused properly
    p = asyncForBytes(f, 5, doc, 0);
    final ByteQuadsCanonicalizer symbols2 = ((NonBlockingJsonParserBase) p.parser()).symbolTableForTests();
    // symbol tables are not reused, but contents are:
    assertNotSame(symbols1, symbols2);
    assertEquals(3, symbols2.size());
    assertEquals(JsonToken.START_OBJECT, p.nextToken());
    assertEquals(JsonToken.FIELD_NAME, p.nextToken());
    // field names are interned:
    assertEquals(STR1, p.currentName());
    assertEquals(3, symbols2.size());
    assertEquals(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertEquals(JsonToken.FIELD_NAME, p.nextToken());
    assertEquals("foobar", p.currentName());
    assertEquals(3, symbols2.size());
    assertEquals(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertEquals(JsonToken.FIELD_NAME, p.nextToken());
    assertEquals("longername", p.currentName());
    assertEquals(3, symbols2.size());
    assertEquals(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertEquals(JsonToken.END_OBJECT, p.nextToken());
    assertNull(p.nextToken());
    assertEquals(3, symbols2.size());
    p.close();
    assertEquals(3, symbols2.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)

Aggregations

JsonFactory (com.fasterxml.jackson.core.json.JsonFactory)2 NonBlockingJsonParserBase (com.fasterxml.jackson.core.json.async.NonBlockingJsonParserBase)2 ByteQuadsCanonicalizer (com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer)2 AsyncReaderWrapper (com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)2