use of com.fasterxml.jackson.core.json.JsonFactory in project jackson-core by FasterXML.
the class TestSymbolsWithMediaItem method testSmallSymbolSetWithChars.
public void testSmallSymbolSetWithChars() throws IOException {
final int SEED = 33333;
CharsToNameCanonicalizer symbols = CharsToNameCanonicalizer.createRoot(SEED).makeChild(-1);
JsonFactory f = new JsonFactory();
JsonParser p = f.createParser(ObjectReadContext.empty(), JSON);
JsonToken t;
while ((t = p.nextToken()) != null) {
if (t != JsonToken.FIELD_NAME) {
continue;
}
String name = p.currentName();
char[] ch = name.toCharArray();
symbols.findSymbol(ch, 0, ch.length, symbols.calcHash(name));
}
p.close();
assertEquals(13, symbols.size());
assertEquals(13, symbols.size());
assertEquals(64, symbols.bucketCount());
// usually get 1 collision, but sometimes get lucky with 0; other times less so with 2
// (with differing shifting for hash etc)
assertEquals(0, symbols.collisionCount());
assertEquals(0, symbols.maxCollisionLength());
}
use of com.fasterxml.jackson.core.json.JsonFactory in project jackson-core by FasterXML.
the class AsyncNonStdNumbersTest method testAllowNaN.
public void testAllowNaN() throws Exception {
final String JSON = "[ NaN]";
JsonFactory f = JsonFactory.builder().enable(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS).build();
_testAllowNaN(f, JSON, 99);
_testAllowNaN(f, JSON, 5);
_testAllowNaN(f, JSON, 3);
_testAllowNaN(f, JSON, 2);
_testAllowNaN(f, JSON, 1);
}
use of com.fasterxml.jackson.core.json.JsonFactory 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();
}
use of com.fasterxml.jackson.core.json.JsonFactory in project jackson-core by FasterXML.
the class AsyncRootValuesTest method testTokenRootSequence.
/*
/**********************************************************************
/* Root-level sequences
/**********************************************************************
*/
public void testTokenRootSequence() throws Exception {
byte[] input = _jsonDoc("\n[ true, false,\nnull ,null\n,true,false]");
JsonFactory f = JSON_F;
_testTokenRootSequence(f, input, 0, 900);
_testTokenRootSequence(f, input, 0, 3);
_testTokenRootSequence(f, input, 0, 1);
_testTokenRootSequence(f, input, 1, 900);
_testTokenRootSequence(f, input, 1, 3);
_testTokenRootSequence(f, input, 1, 1);
}
use of com.fasterxml.jackson.core.json.JsonFactory in project jackson-core by FasterXML.
the class AsyncRootValuesTest method testMixedRootSequence.
public void testMixedRootSequence() throws Exception {
ByteArrayOutputStream bytes = new ByteArrayOutputStream(100);
// Let's simply concatenate documents...
bytes.write(_jsonDoc("{ \"a\" : 4 }"));
bytes.write(_jsonDoc("[ 12, -987,false ]"));
bytes.write(_jsonDoc(" 12356"));
bytes.write(_jsonDoc(" true"));
byte[] input = bytes.toByteArray();
JsonFactory f = JSON_F;
_testMixedRootSequence(f, input, 0, 100);
_testMixedRootSequence(f, input, 0, 3);
_testMixedRootSequence(f, input, 0, 1);
_testMixedRootSequence(f, input, 1, 100);
_testMixedRootSequence(f, input, 1, 3);
_testMixedRootSequence(f, input, 1, 1);
}
Aggregations