use of com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper in project jackson-core by FasterXML.
the class AsyncRootValuesTest method _testMixedRootSequence.
private void _testMixedRootSequence(JsonFactory f, byte[] data, int offset, int readSize) throws IOException {
AsyncReaderWrapper r = asyncForBytes(f, readSize, data, offset);
assertNull(r.currentToken());
// { "a":4 }
assertToken(JsonToken.START_OBJECT, r.nextToken());
assertToken(JsonToken.FIELD_NAME, r.nextToken());
assertEquals("a", r.currentName());
assertToken(JsonToken.VALUE_NUMBER_INT, r.nextToken());
assertEquals(4, r.getIntValue());
assertToken(JsonToken.END_OBJECT, r.nextToken());
// [ 12, -987, false]
assertToken(JsonToken.START_ARRAY, r.nextToken());
assertToken(JsonToken.VALUE_NUMBER_INT, r.nextToken());
assertEquals(12, r.getIntValue());
assertToken(JsonToken.VALUE_NUMBER_INT, r.nextToken());
assertEquals(-987, r.getIntValue());
assertToken(JsonToken.VALUE_FALSE, r.nextToken());
assertToken(JsonToken.END_ARRAY, r.nextToken());
assertToken(JsonToken.VALUE_NUMBER_INT, r.nextToken());
assertEquals(12356, r.getIntValue());
assertToken(JsonToken.VALUE_TRUE, r.nextToken());
assertNull(r.nextToken());
assertTrue(r.isClosed());
}
use of com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper in project jackson-core by FasterXML.
the class AsyncScopeMatchingTest method testMismatchArrayToObject.
public void testMismatchArrayToObject() throws Exception {
final String JSON = "[ 1, 2 }";
AsyncReaderWrapper p = asyncForBytes(JSON_F, 3, _jsonDoc(JSON), 0);
assertToken(JsonToken.START_ARRAY, p.nextToken());
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
try {
p.nextToken();
fail("Expected an exception for incorrectly closed ARRAY");
} catch (JsonParseException pe) {
verifyException(pe, "Unexpected close marker '}': expected ']'");
}
p.close();
}
use of com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper in project jackson-core by FasterXML.
the class AsyncScopeMatchingTest method testUnclosedArray.
public void testUnclosedArray(int mode) throws Exception {
AsyncReaderWrapper p = asyncForBytes(JSON_F, 3, _jsonDoc("[ 1, 2 "), 0);
assertToken(JsonToken.START_ARRAY, p.nextToken());
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
assertEquals(2, p.getIntValue());
try {
p.nextToken();
fail("Expected an exception for unclosed ARRAY (mode: " + mode + ")");
} catch (JsonParseException pe) {
verifyException(pe, "expected close marker for ARRAY");
}
}
use of com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper in project jackson-core by FasterXML.
the class AsyncScopeMatchingTest method testEOFInName.
public void testEOFInName(int mode) throws Exception {
final String JSON = "{ \"abcd";
AsyncReaderWrapper p = asyncForBytes(JSON_F, 3, _jsonDoc(JSON), 0);
assertToken(JsonToken.START_OBJECT, p.nextToken());
try {
p.nextToken();
fail("Expected an exception for EOF");
} catch (JsonParseException pe) {
verifyException(pe, "Unexpected end-of-input");
} catch (IOException ie) {
// DataInput behaves bit differently
if (mode == MODE_DATA_INPUT) {
verifyException(ie, "end-of-input");
return;
}
}
}
use of com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper in project jackson-core by FasterXML.
the class AsyncMissingValuesInObjectTest method testObjectTrailingCommas.
@Test
public void testObjectTrailingCommas() throws Exception {
String json = "{\"a\": true, \"b\": false,,}";
AsyncReaderWrapper p = createParser(factory, json);
assertEquals(JsonToken.START_OBJECT, p.nextToken());
assertToken(JsonToken.FIELD_NAME, p.nextToken());
assertEquals("a", p.currentText());
assertToken(JsonToken.VALUE_TRUE, p.nextToken());
assertToken(JsonToken.FIELD_NAME, p.nextToken());
assertEquals("b", p.currentText());
assertToken(JsonToken.VALUE_FALSE, p.nextToken());
assertUnexpected(p, ',');
p.close();
}
Aggregations