Search in sources :

Example 11 with StreamReadException

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

the class AsyncScopeMatchingTest method testMismatchObjectToArray.

public void testMismatchObjectToArray() throws Exception {
    final String JSON = "{ ]";
    AsyncReaderWrapper p = asyncForBytes(JSON_F, 3, _jsonDoc(JSON), 0);
    assertToken(JsonToken.START_OBJECT, p.nextToken());
    try {
        p.nextToken();
        fail("Expected an exception for incorrectly closed OBJECT");
    } 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)

Example 12 with StreamReadException

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

the class AsyncSimpleNestedTest method _testMismatchedObject.

private void _testMismatchedObject(JsonFactory f, byte[] data, int offset, int readSize) {
    AsyncReaderWrapper r = asyncForBytes(f, readSize, data, offset);
    assertToken(JsonToken.START_OBJECT, r.nextToken());
    try {
        r.nextToken();
        fail("Should not pass");
    } catch (StreamReadException e) {
        verifyException(e, "Unexpected close marker ']': expected '}'");
    }
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 13 with StreamReadException

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

the class AsyncSimpleNestedTest method _testMismatchedArray.

private void _testMismatchedArray(JsonFactory f, byte[] data, int offset, int readSize) {
    AsyncReaderWrapper r = asyncForBytes(f, readSize, data, offset);
    assertToken(JsonToken.START_ARRAY, r.nextToken());
    try {
        r.nextToken();
        fail("Should not pass");
    } catch (StreamReadException e) {
        verifyException(e, "Unexpected close marker '}': expected ']'");
    }
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 14 with StreamReadException

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

the class AsyncSimpleObjectTest method _testBooleans.

private void _testBooleans(JsonFactory f, byte[] data, int offset, int readSize) {
    AsyncReaderWrapper r = asyncForBytes(f, readSize, data, offset);
    // start with "no token"
    assertNull(r.currentToken());
    assertToken(JsonToken.START_OBJECT, r.nextToken());
    assertToken(JsonToken.PROPERTY_NAME, r.nextToken());
    assertEquals("a", r.currentText());
    // by default no cheap access to char[] version:
    assertFalse(r.parser().hasTextCharacters());
    // but...
    char[] ch = r.parser().getTextCharacters();
    assertEquals(0, r.parser().getTextOffset());
    assertEquals(1, r.parser().getTextLength());
    assertEquals("a", new String(ch, 0, 1));
    assertTrue(r.parser().hasTextCharacters());
    assertToken(JsonToken.VALUE_TRUE, r.nextToken());
    assertToken(JsonToken.PROPERTY_NAME, r.nextToken());
    assertEquals("b", r.currentText());
    assertToken(JsonToken.VALUE_FALSE, r.nextToken());
    assertToken(JsonToken.PROPERTY_NAME, r.nextToken());
    assertEquals("acdc", r.currentText());
    assertToken(JsonToken.VALUE_TRUE, r.nextToken());
    assertToken(JsonToken.PROPERTY_NAME, r.nextToken());
    assertEquals(UNICODE_SHORT_NAME, r.currentText());
    assertToken(JsonToken.VALUE_TRUE, r.nextToken());
    assertToken(JsonToken.PROPERTY_NAME, r.nextToken());
    assertEquals("a1234567", r.currentText());
    assertToken(JsonToken.VALUE_FALSE, r.nextToken());
    assertToken(JsonToken.PROPERTY_NAME, r.nextToken());
    assertEquals(UNICODE_LONG_NAME, r.currentText());
    assertToken(JsonToken.VALUE_TRUE, r.nextToken());
    // and for fun let's verify can't access this as number or binary
    try {
        r.getDoubleValue();
        fail("Should not pass");
    } catch (InputCoercionException e) {
        verifyException(e, "Current token (VALUE_TRUE) not numeric");
    }
    try {
        r.parser().getBinaryValue();
        fail("Should not pass");
    } catch (StreamReadException e) {
        verifyException(e, "Current token (VALUE_TRUE) not");
        verifyException(e, "can not access as binary");
    }
    assertToken(JsonToken.END_OBJECT, r.nextToken());
    // and end up with "no token" as well
    assertNull(r.nextToken());
    assertTrue(r.isClosed());
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) InputCoercionException(com.fasterxml.jackson.core.exc.InputCoercionException) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 15 with StreamReadException

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

the class NonStandardJsonReadFeaturesTest method _testNonStandarBackslashQuoting.

/*
    /****************************************************************
    /* Secondary test methods
    /****************************************************************
     */
private void _testNonStandarBackslashQuoting(int mode) {
    // first: verify that we get an exception
    final String JSON = quote("\\'");
    JsonParser p = createParser(STD_F, mode, JSON);
    try {
        p.nextToken();
        p.getText();
        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...
    JsonFactory f = JsonFactory.builder().configure(JsonReadFeature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER, true).build();
    p = createParser(f, mode, JSON);
    assertToken(JsonToken.VALUE_STRING, p.nextToken());
    assertEquals("'", p.getText());
    p.close();
}
Also used : 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