use of com.fasterxml.jackson.core.exc.StreamReadException in project jackson-core by FasterXML.
the class AsyncScopeMatchingTest method testMismatchObjectToArray.
public void testMismatchObjectToArray() throws Exception {
final String JSON = "{ ]";
AsyncReaderWrapper p = asyncForBytes(JSON_F, 3, _jsonDoc(JSON), 0);
assertToken(JsonToken.START_OBJECT, p.nextToken());
try {
p.nextToken();
fail("Expected an exception for incorrectly closed OBJECT");
} catch (StreamReadException pe) {
verifyException(pe, "Unexpected close marker ']': expected '}'");
}
p.close();
}
use of com.fasterxml.jackson.core.exc.StreamReadException in project jackson-core by FasterXML.
the class AsyncSimpleNestedTest method _testMismatchedObject.
private void _testMismatchedObject(JsonFactory f, byte[] data, int offset, int readSize) {
AsyncReaderWrapper r = asyncForBytes(f, readSize, data, offset);
assertToken(JsonToken.START_OBJECT, r.nextToken());
try {
r.nextToken();
fail("Should not pass");
} catch (StreamReadException e) {
verifyException(e, "Unexpected close marker ']': expected '}'");
}
}
use of com.fasterxml.jackson.core.exc.StreamReadException in project jackson-core by FasterXML.
the class AsyncSimpleNestedTest method _testMismatchedArray.
private void _testMismatchedArray(JsonFactory f, byte[] data, int offset, int readSize) {
AsyncReaderWrapper r = asyncForBytes(f, readSize, data, offset);
assertToken(JsonToken.START_ARRAY, r.nextToken());
try {
r.nextToken();
fail("Should not pass");
} catch (StreamReadException e) {
verifyException(e, "Unexpected close marker '}': expected ']'");
}
}
use of com.fasterxml.jackson.core.exc.StreamReadException in project jackson-core by FasterXML.
the class AsyncSimpleObjectTest method _testBooleans.
private void _testBooleans(JsonFactory f, byte[] data, int offset, int readSize) {
AsyncReaderWrapper r = asyncForBytes(f, readSize, data, offset);
// start with "no token"
assertNull(r.currentToken());
assertToken(JsonToken.START_OBJECT, r.nextToken());
assertToken(JsonToken.PROPERTY_NAME, r.nextToken());
assertEquals("a", r.currentText());
// by default no cheap access to char[] version:
assertFalse(r.parser().hasTextCharacters());
// but...
char[] ch = r.parser().getTextCharacters();
assertEquals(0, r.parser().getTextOffset());
assertEquals(1, r.parser().getTextLength());
assertEquals("a", new String(ch, 0, 1));
assertTrue(r.parser().hasTextCharacters());
assertToken(JsonToken.VALUE_TRUE, r.nextToken());
assertToken(JsonToken.PROPERTY_NAME, r.nextToken());
assertEquals("b", r.currentText());
assertToken(JsonToken.VALUE_FALSE, r.nextToken());
assertToken(JsonToken.PROPERTY_NAME, r.nextToken());
assertEquals("acdc", r.currentText());
assertToken(JsonToken.VALUE_TRUE, r.nextToken());
assertToken(JsonToken.PROPERTY_NAME, r.nextToken());
assertEquals(UNICODE_SHORT_NAME, r.currentText());
assertToken(JsonToken.VALUE_TRUE, r.nextToken());
assertToken(JsonToken.PROPERTY_NAME, r.nextToken());
assertEquals("a1234567", r.currentText());
assertToken(JsonToken.VALUE_FALSE, r.nextToken());
assertToken(JsonToken.PROPERTY_NAME, r.nextToken());
assertEquals(UNICODE_LONG_NAME, r.currentText());
assertToken(JsonToken.VALUE_TRUE, r.nextToken());
// and for fun let's verify can't access this as number or binary
try {
r.getDoubleValue();
fail("Should not pass");
} catch (InputCoercionException e) {
verifyException(e, "Current token (VALUE_TRUE) not numeric");
}
try {
r.parser().getBinaryValue();
fail("Should not pass");
} catch (StreamReadException e) {
verifyException(e, "Current token (VALUE_TRUE) not");
verifyException(e, "can not access as binary");
}
assertToken(JsonToken.END_OBJECT, r.nextToken());
// and end up with "no token" as well
assertNull(r.nextToken());
assertTrue(r.isClosed());
}
use of com.fasterxml.jackson.core.exc.StreamReadException in project jackson-core by FasterXML.
the class NonStandardJsonReadFeaturesTest method _testNonStandarBackslashQuoting.
/*
/****************************************************************
/* Secondary test methods
/****************************************************************
*/
private void _testNonStandarBackslashQuoting(int mode) {
// first: verify that we get an exception
final String JSON = quote("\\'");
JsonParser p = createParser(STD_F, mode, JSON);
try {
p.nextToken();
p.getText();
fail("Should have thrown an exception for doc <" + JSON + ">");
} catch (StreamReadException e) {
verifyException(e, "unrecognized character escape");
} finally {
p.close();
}
// and then verify it's ok...
JsonFactory f = JsonFactory.builder().configure(JsonReadFeature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER, true).build();
p = createParser(f, mode, JSON);
assertToken(JsonToken.VALUE_STRING, p.nextToken());
assertEquals("'", p.getText());
p.close();
}
Aggregations