Search in sources :

Example 6 with StreamReadException

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

the class AsyncNonStdParsingTest method _testSingleQuotesDefault.

private void _testSingleQuotesDefault(JsonFactory f, int offset, int readSize) {
    // First, let's see that by default they are not allowed
    String JSON = "[ 'text' ]";
    AsyncReaderWrapper p = createParser(f, JSON, offset, readSize);
    assertToken(JsonToken.START_ARRAY, p.nextToken());
    try {
        p.nextToken();
        fail("Expected exception");
    } catch (StreamReadException e) {
        verifyException(e, "Unexpected character ('''");
    } finally {
        p.close();
    }
    JSON = "{ 'a':1 }";
    p = createParser(f, JSON, offset, readSize);
    assertToken(JsonToken.START_OBJECT, p.nextToken());
    try {
        p.nextToken();
        fail("Expected exception");
    } catch (StreamReadException e) {
        verifyException(e, "Unexpected character ('''");
    } finally {
        p.close();
    }
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 7 with StreamReadException

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

the class AsyncScopeMatchingTest method testEOFInName.

public void testEOFInName() 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 (StreamReadException pe) {
        verifyException(pe, "Unexpected end-of-input");
    }
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 8 with StreamReadException

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

the class AsyncScopeMatchingTest method testUnclosedObject.

public void testUnclosedObject() throws Exception {
    AsyncReaderWrapper p = asyncForBytes(JSON_F, 3, _jsonDoc("{ \"key\" : 3  "), 0);
    assertToken(JsonToken.START_OBJECT, p.nextToken());
    assertToken(JsonToken.PROPERTY_NAME, p.nextToken());
    assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    try {
        p.nextToken();
        fail("Expected an exception for unclosed OBJECT");
    } catch (StreamReadException pe) {
        verifyException(pe, "expected an Object property name or END_ARRAY");
    }
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 9 with StreamReadException

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

the class AsyncScopeMatchingTest method testMisssingColon.

public void testMisssingColon() throws Exception {
    final String JSON = "{ \"a\" \"b\" }";
    AsyncReaderWrapper p = asyncForBytes(JSON_F, 3, _jsonDoc(JSON), 0);
    assertToken(JsonToken.START_OBJECT, p.nextToken());
    try {
        // can be either here, or with next one...
        assertToken(JsonToken.PROPERTY_NAME, p.nextToken());
        p.nextToken();
        fail("Expected an exception for missing semicolon");
    } catch (StreamReadException pe) {
        verifyException(pe, "was expecting a colon");
    }
    p.close();
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 10 with StreamReadException

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

the class AsyncScopeMatchingTest method testUnclosedArray.

public void testUnclosedArray() 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");
    } catch (StreamReadException pe) {
        verifyException(pe, "expected a value token");
    }
}
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