Search in sources :

Example 31 with JsonParseException

use of com.fasterxml.jackson.core.JsonParseException in project underlx by underlx.

the class API method putTrip.

public Trip putTrip(TripRequest request) throws APIException {
    try {
        byte[] content = mapper.writeValueAsBytes(request);
        InputStream is = putRequest(endpoint.resolve("trips"), content, true);
        return mapper.readValue(is, Trip.class);
    } catch (JsonParseException e) {
        throw new APIException(e).addInfo("Parse exception");
    } catch (JsonMappingException e) {
        throw new APIException(e).addInfo("Mapping exception");
    } catch (IOException e) {
        throw new APIException(e).addInfo("IOException");
    }
}
Also used : APIException(im.tny.segvault.disturbances.exception.APIException) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException)

Example 32 with JsonParseException

use of com.fasterxml.jackson.core.JsonParseException in project underlx by underlx.

the class API method postTrip.

public Trip postTrip(TripRequest request) throws APIException {
    try {
        byte[] content = mapper.writeValueAsBytes(request);
        InputStream is = postRequest(endpoint.resolve("trips"), content, true);
        return mapper.readValue(is, Trip.class);
    } catch (JsonParseException e) {
        throw new APIException(e).addInfo("Parse exception");
    } catch (JsonMappingException e) {
        throw new APIException(e).addInfo("Mapping exception");
    } catch (IOException e) {
        throw new APIException(e).addInfo("IOException");
    }
}
Also used : APIException(im.tny.segvault.disturbances.exception.APIException) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException)

Example 33 with JsonParseException

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

the class ParserErrorHandlingTest method _testMangledNumbersFloat.

private void _testMangledNumbersFloat(int mode) throws Exception {
    // Also test with floats
    JsonParser p = createParser(mode, "1.5false");
    try {
        JsonToken t = p.nextToken();
        fail("Should have gotten an exception; instead got token: " + t);
    } catch (JsonParseException e) {
        verifyException(e, "expected space");
    }
    p.close();
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken) JsonParseException(com.fasterxml.jackson.core.JsonParseException) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 34 with JsonParseException

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

the class ParserErrorHandlingTest method _testMangledNumbersInt.

private void _testMangledNumbersInt(int mode) throws Exception {
    JsonParser p = createParser(mode, "123true");
    try {
        JsonToken t = p.nextToken();
        fail("Should have gotten an exception; instead got token: " + t);
    } catch (JsonParseException e) {
        verifyException(e, "expected space");
    }
    p.close();
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken) JsonParseException(com.fasterxml.jackson.core.JsonParseException) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 35 with JsonParseException

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

the class AsyncNumberCoercionTest method testToLongFailing.

public void testToLongFailing() throws Exception {
    AsyncReaderWrapper p;
    // BigInteger -> error
    BigInteger big = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.TEN);
    p = createParser(String.valueOf(big));
    assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertEquals(NumberType.BIG_INTEGER, p.getNumberType());
    assertEquals(big, p.getBigIntegerValue());
    assertEquals(big, p.getNumberValue());
    try {
        p.getLongValue();
        fail("Should not pass");
    } catch (JsonParseException e) {
        verifyException(e, "out of range of long");
    }
    BigInteger small = BigInteger.valueOf(Long.MIN_VALUE).subtract(BigInteger.TEN);
    p = createParser(String.valueOf(small));
    assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertEquals(small, p.getBigIntegerValue());
    try {
        p.getLongValue();
        fail("Should not pass");
    } catch (JsonParseException e) {
        verifyException(e, "out of range of long");
    }
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) BigInteger(java.math.BigInteger) JsonParseException(com.fasterxml.jackson.core.JsonParseException)

Aggregations

JsonParseException (com.fasterxml.jackson.core.JsonParseException)120 IOException (java.io.IOException)59 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)53 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)31 JsonParser (com.fasterxml.jackson.core.JsonParser)21 Map (java.util.Map)15 JsonNode (com.fasterxml.jackson.databind.JsonNode)14 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)13 InputStream (java.io.InputStream)12 HashMap (java.util.HashMap)12 JsonToken (com.fasterxml.jackson.core.JsonToken)11 JsonFactory (com.fasterxml.jackson.core.JsonFactory)9 File (java.io.File)9 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)7 JsonLocation (com.fasterxml.jackson.core.JsonLocation)6 Date (java.util.Date)5 GZIPInputStream (java.util.zip.GZIPInputStream)5 TypeReference (com.fasterxml.jackson.core.type.TypeReference)4 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)4