Search in sources :

Example 56 with StreamReadException

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();
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 57 with StreamReadException

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();
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) JsonFactory(com.fasterxml.jackson.core.json.JsonFactory) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 58 with StreamReadException

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();
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) JsonFactory(com.fasterxml.jackson.core.json.JsonFactory) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 59 with StreamReadException

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();
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) JsonFactory(com.fasterxml.jackson.core.json.JsonFactory) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 60 with StreamReadException

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();
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Aggregations

StreamReadException (com.fasterxml.jackson.core.exc.StreamReadException)68 AsyncReaderWrapper (com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)23 JsonParser (com.fasterxml.jackson.core.JsonParser)15 JsonFactory (com.fasterxml.jackson.core.json.JsonFactory)11 CBORParser (com.fasterxml.jackson.dataformat.cbor.CBORParser)9 JsonToken (com.fasterxml.jackson.core.JsonToken)6 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayFeeder (com.fasterxml.jackson.core.async.ByteArrayFeeder)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 URL (java.net.URL)2 Test (org.junit.Test)2 InputCoercionException (com.fasterxml.jackson.core.exc.InputCoercionException)1 WrappedIOException (com.fasterxml.jackson.core.exc.WrappedIOException)1 FilteringParserDelegate (com.fasterxml.jackson.core.filter.FilteringParserDelegate)1 ByteQuadsCanonicalizer (com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 SmileGenerator (com.fasterxml.jackson.dataformat.smile.SmileGenerator)1 SmileMapper (com.fasterxml.jackson.dataformat.smile.databind.SmileMapper)1 ThrottledInputStream (com.fasterxml.jackson.dataformat.smile.testutil.ThrottledInputStream)1