Search in sources :

Example 36 with JsonMappingException

use of com.fasterxml.jackson.databind.JsonMappingException in project underlx by underlx.

the class API method postFeedback.

public Feedback postFeedback(Feedback request) throws APIException {
    try {
        byte[] content = mapper.writeValueAsBytes(request);
        InputStream is = postRequest(endpoint.resolve("feedback"), content, true);
        return mapper.readValue(is, Feedback.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 37 with JsonMappingException

use of com.fasterxml.jackson.databind.JsonMappingException 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 38 with JsonMappingException

use of com.fasterxml.jackson.databind.JsonMappingException 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 39 with JsonMappingException

use of com.fasterxml.jackson.databind.JsonMappingException in project candlepin by candlepin.

the class ListenerWrapperTest method whenMapperReadThrowsExceptionThenOnMessageShouldFail.

@Test(expected = RuntimeException.class)
public void whenMapperReadThrowsExceptionThenOnMessageShouldFail() throws Exception {
    doReturn("test123").when(activeMQBuffer).readString();
    doThrow(new JsonMappingException("Induced exception")).when(mapper).readValue(anyString(), eq(Event.class));
    this.listenerWrapper.onMessage(mockClientMessage);
}
Also used : JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) Test(org.junit.Test)

Example 40 with JsonMappingException

use of com.fasterxml.jackson.databind.JsonMappingException in project candlepin by candlepin.

the class ReaderExceptionMapperTest method handleJsonMappingExceptionWithResponse.

@Test
public void handleJsonMappingExceptionWithResponse() {
    Response mockr = mock(Response.class);
    when(mockr.getStatus()).thenReturn(400);
    ReaderException nfe = new ReaderException("kaboom", new JsonMappingException("nope"));
    ReaderExceptionMapper nfem = injector.getInstance(ReaderExceptionMapper.class);
    Response r = nfem.toResponse(nfe);
    assertEquals(400, r.getStatus());
    verifyMessage(r, rtmsg("kaboom"));
}
Also used : Response(javax.ws.rs.core.Response) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) ReaderException(org.jboss.resteasy.spi.ReaderException) Test(org.junit.Test)

Aggregations

JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)147 IOException (java.io.IOException)75 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)62 JsonParseException (com.fasterxml.jackson.core.JsonParseException)53 Test (org.junit.Test)28 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)23 ArrayList (java.util.ArrayList)16 HashMap (java.util.HashMap)16 JsonNode (com.fasterxml.jackson.databind.JsonNode)14 File (java.io.File)14 Map (java.util.Map)14 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)11 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)10 InputStream (java.io.InputStream)9 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 List (java.util.List)7 Writer (org.alfresco.rest.framework.jacksonextensions.JacksonHelper.Writer)7 Test (org.junit.jupiter.api.Test)6 SimpleFilterProvider (com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider)5