Search in sources :

Example 61 with StreamReadException

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

the class AsyncTokenFilterTest method testSkipChildrenFailOnSplit.

public void testSkipChildrenFailOnSplit() {
    NonBlockingJsonParser nbParser = _nonBlockingParser();
    FilteringParserDelegate filteredParser = new FilteringParserDelegate(nbParser, TOKEN_FILTER, Inclusion.INCLUDE_ALL_AND_PATH, true);
    nbParser.feedInput(INPUT_BYTES, 0, 5);
    assertToken(JsonToken.START_OBJECT, nbParser.nextToken());
    try {
        nbParser.skipChildren();
        fail("Should not pass!");
    } catch (StreamReadException e) {
        verifyException(e, "not enough content available");
        verifyException(e, "skipChildren()");
    }
    filteredParser.close();
    nbParser.close();
}
Also used : FilteringParserDelegate(com.fasterxml.jackson.core.filter.FilteringParserDelegate) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 62 with StreamReadException

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

the class ArrayParsingTest method _testMissingValueNotEnablingFeature.

private void _testMissingValueNotEnablingFeature(boolean useStream) throws Exception {
    final String DOC = "[ \"a\",,\"abc\"] ";
    JsonFactory f = new JsonFactory();
    JsonParser p = useStream ? createParserUsingStream(f, DOC, "UTF-8") : createParserUsingReader(f, DOC);
    assertToken(JsonToken.START_ARRAY, p.nextToken());
    assertToken(JsonToken.VALUE_STRING, p.nextToken());
    assertEquals("a", p.getValueAsString());
    try {
        assertToken(JsonToken.VALUE_STRING, p.nextToken());
        fail("Expecting exception here");
    } catch (StreamReadException ex) {
        verifyException(ex, "expected a valid value", "expected a value");
    }
    p.close();
}
Also used : JsonFactory(com.fasterxml.jackson.core.json.JsonFactory) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 63 with StreamReadException

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

the class NonStandardAposQuotedNamesTest method _testSingleQuotesDefault.

/*
    /****************************************************************
    /* Secondary test methods
    /****************************************************************
     */
/**
 * Test to verify that the default parser settings do not
 * accept single-quotes for String values (field names,
 * textual values)
 */
private void _testSingleQuotesDefault(int mode) throws Exception {
    // First, let's see that by default they are not allowed
    String JSON = "[ 'text' ]";
    try (JsonParser p = createParser(STD_F, mode, JSON)) {
        assertToken(JsonToken.START_ARRAY, p.nextToken());
        p.nextToken();
        fail("Expected exception");
    } catch (StreamReadException e) {
        verifyException(e, "Unexpected character ('''");
    }
    JSON = "{ 'a':1 }";
    try (JsonParser p = createParser(STD_F, mode, JSON)) {
        assertToken(JsonToken.START_OBJECT, p.nextToken());
        p.nextToken();
        fail("Expected exception");
    } catch (StreamReadException e) {
        verifyException(e, "Unexpected character ('''");
    }
}
Also used : StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 64 with StreamReadException

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

the class ParserErrorHandlingTest method doTestInvalidKeyword1.

private void doTestInvalidKeyword1(int mode, String value) {
    String doc = "{ \"key1\" : " + value + " }";
    JsonParser p = createParser(mode, doc);
    assertToken(JsonToken.START_OBJECT, p.nextToken());
    // get the exception early or late...
    try {
        assertToken(JsonToken.PROPERTY_NAME, p.nextToken());
        p.nextToken();
        fail("Expected an exception for malformed value keyword");
    } catch (StreamReadException jex) {
        verifyException(jex, "Unrecognized token");
        verifyException(jex, value);
    } finally {
        p.close();
    }
    // Try as root-level value as well:
    // may need space after for DataInput
    doc = value + " ";
    p = createParser(mode, doc);
    try {
        p.nextToken();
        fail("Expected an exception for malformed value keyword");
    } catch (StreamReadException jex) {
        verifyException(jex, "Unrecognized token");
        verifyException(jex, value);
    } finally {
        p.close();
    }
}
Also used : StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 65 with StreamReadException

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

the class AsyncReaderWrapperForByteArray method nextToken.

@Override
public JsonToken nextToken() {
    JsonToken token;
    while ((token = _streamReader.nextToken()) == JsonToken.NOT_AVAILABLE) {
        ByteArrayFeeder feeder = (ByteArrayFeeder) _streamReader.nonBlockingInputFeeder();
        if (!feeder.needMoreInput()) {
            throw new StreamReadException(null, "Got NOT_AVAILABLE, could not feed more input");
        }
        int amount = Math.min(_bytesPerFeed, _end - _offset);
        if (amount < 1) {
            // end-of-input?
            feeder.endOfInput();
        } else {
            // padding?
            if (_padding == 0) {
                feeder.feedInput(_doc, _offset, _offset + amount);
            } else {
                byte[] tmp = new byte[amount + _padding + _padding];
                System.arraycopy(_doc, _offset, tmp, _padding, amount);
                feeder.feedInput(tmp, _padding, _padding + amount);
            }
            _offset += amount;
        }
    }
    return token;
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException) ByteArrayFeeder(com.fasterxml.jackson.core.async.ByteArrayFeeder)

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