Search in sources :

Example 1 with StreamReadException

use of com.fasterxml.jackson.core.exc.StreamReadException in project jackson-core by FasterXML.

the class AsyncCharEscapingTest method _testMissingLinefeedEscaping.

private void _testMissingLinefeedEscaping(byte[] doc, int offset, int readSize) throws Exception {
    AsyncReaderWrapper r = asyncForBytes(JSON_F, readSize, doc, offset);
    assertToken(JsonToken.START_ARRAY, r.nextToken());
    try {
        // This may or may not trigger exception
        JsonToken t = r.nextToken();
        assertToken(JsonToken.VALUE_STRING, t);
        fail("Expected an exception for un-escaped linefeed in string value");
    } catch (StreamReadException jex) {
        verifyException(jex, "has to be escaped");
    }
    r.close();
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 2 with StreamReadException

use of com.fasterxml.jackson.core.exc.StreamReadException in project jackson-core by FasterXML.

the class AsyncCommentParsingTest method _testDisabled.

private void _testDisabled(String doc) throws IOException {
    AsyncReaderWrapper p = _createParser(doc, false, 3);
    assertToken(JsonToken.START_ARRAY, p.nextToken());
    try {
        p.nextToken();
        fail("Expected exception for unrecognized comment");
    } catch (StreamReadException je) {
        // Should have something denoting that user may want to enable 'ALLOW_COMMENTS'
        verifyException(je, "ALLOW_COMMENTS");
    }
    p.close();
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 3 with StreamReadException

use of com.fasterxml.jackson.core.exc.StreamReadException in project jackson-core by FasterXML.

the class AsyncInvalidCharsTest method _testHandlingOfInvalidSpace.

private void _testHandlingOfInvalidSpace(int offset, int readSize) throws Exception {
    final String doc = "{ \u0008 \"a\":1}";
    AsyncReaderWrapper p = asyncForBytes(JSON_F, readSize, _jsonDoc(doc), offset);
    assertToken(JsonToken.START_OBJECT, p.nextToken());
    try {
        p.nextToken();
        fail("Should have failed");
    } catch (StreamReadException e) {
        verifyException(e, "Illegal character");
        // and correct error code
        verifyException(e, "code 8");
    }
    p.close();
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 4 with StreamReadException

use of com.fasterxml.jackson.core.exc.StreamReadException in project jackson-core by FasterXML.

the class AsyncInvalidCharsTest method _testUTF8BomFail.

private void _testUTF8BomFail(int offset, int readSize, int okBytes, String verify) throws Exception {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    bytes.write(0xEF);
    if (okBytes > 1) {
        bytes.write(0xBB);
    }
    bytes.write("[ 1 ]".getBytes("UTF-8"));
    byte[] doc = bytes.toByteArray();
    AsyncReaderWrapper p = asyncForBytes(JSON_F, readSize, doc, offset);
    try {
        assertEquals(JsonToken.START_ARRAY, p.nextToken());
        fail("Should not pass");
    } catch (StreamReadException e) {
        verifyException(e, verify);
    }
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 5 with StreamReadException

use of com.fasterxml.jackson.core.exc.StreamReadException in project jackson-core by FasterXML.

the class AsyncNonStdParsingTest method _testNonStandarBackslashQuoting.

private void _testNonStandarBackslashQuoting(int offset, int readSize) {
    // first: verify that we get an exception
    JsonFactory f = new JsonFactory();
    final String JSON = quote("\\'");
    AsyncReaderWrapper p = createParser(f, JSON, offset, readSize);
    try {
        p.nextToken();
        p.currentText();
        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...
    f = f.rebuild().enable(JsonReadFeature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER).build();
    p = createParser(f, JSON, offset, readSize);
    assertToken(JsonToken.VALUE_STRING, p.nextToken());
    assertEquals("'", 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)

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