use of com.fasterxml.jackson.core.exc.StreamReadException in project jackson-core by FasterXML.
the class AsyncTokenErrorTest method testMangledRootFloats.
public void testMangledRootFloats() {
// Also test with floats
AsyncReaderWrapper p = _createParser("1.5false");
try {
JsonToken t = p.nextToken();
fail("Should have gotten an exception; instead got token: " + t + "; number: " + p.getNumberValue());
} catch (StreamReadException e) {
verifyException(e, "expected space");
}
p.close();
}
use of com.fasterxml.jackson.core.exc.StreamReadException in project jackson-core by FasterXML.
the class AsyncNonStdNumberHandlingTest method _testLeadingZeroesFloat.
private void _testLeadingZeroesFloat(String valueStr, double value) {
// first: verify that we get an exception
JsonFactory f = new JsonFactory();
String JSON = valueStr;
AsyncReaderWrapper p = createParser(f, JSON);
try {
p.nextToken();
p.currentText();
fail("Should have thrown an exception for doc <" + JSON + ">");
} catch (StreamReadException e) {
verifyException(e, "invalid numeric value");
} finally {
p.close();
}
// and then verify it's ok when enabled
f = f.rebuild().enable(JsonReadFeature.ALLOW_LEADING_ZEROS_FOR_NUMBERS).build();
p = createParser(f, JSON);
assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
assertEquals(String.valueOf(value), p.currentText());
assertEquals(value, p.getDoubleValue());
p.close();
}
use of com.fasterxml.jackson.core.exc.StreamReadException in project jackson-core by FasterXML.
the class AsyncNonStdNumberHandlingTest method _testLeadingPeriodFloat.
private void _testLeadingPeriodFloat(String valueStr, double value, int bytesPerRead) {
// first: verify that we get an exception
JsonFactory f = new JsonFactory();
String JSON = valueStr;
AsyncReaderWrapper p = createParser(f, JSON, bytesPerRead);
try {
p.nextToken();
p.currentText();
fail("Should have thrown an exception for doc <" + JSON + ">");
} catch (StreamReadException e) {
verifyException(e, "Unexpected character ('.'");
verifyException(e, "expected a valid value");
} finally {
p.close();
}
// and then verify it's ok when enabled
f = JsonFactory.builder().enable(JsonReadFeature.ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS).build();
p = createParser(f, JSON, bytesPerRead);
assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
assertEquals(value, p.getDoubleValue());
assertEquals(valueStr.trim(), p.currentText());
p.close();
}
use of com.fasterxml.jackson.core.exc.StreamReadException in project jackson-core by FasterXML.
the class AsyncNonStdNumberHandlingTest method _testLeadingZeroesInt.
public void _testLeadingZeroesInt(String valueStr, int value) {
// first: verify that we get an exception
JsonFactory f = new JsonFactory();
String JSON = valueStr;
AsyncReaderWrapper p = createParser(f, JSON);
try {
p.nextToken();
p.currentText();
fail("Should have thrown an exception for doc <" + JSON + ">");
} catch (StreamReadException e) {
verifyException(e, "invalid numeric value");
} finally {
p.close();
}
// and then verify it's ok when enabled
f = f.rebuild().enable(JsonReadFeature.ALLOW_LEADING_ZEROS_FOR_NUMBERS).build();
p = createParser(f, JSON);
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
assertEquals(value, p.getIntValue());
assertEquals(String.valueOf(value), p.currentText());
p.close();
}
use of com.fasterxml.jackson.core.exc.StreamReadException 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 (StreamReadException pe) {
verifyException(pe, "Unexpected close marker '}': expected ']'");
}
p.close();
}
Aggregations