Example usage for com.fasterxml.jackson.databind JsonMappingException getCause

List of usage examples for com.fasterxml.jackson.databind JsonMappingException getCause

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind JsonMappingException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:com.mapr.synth.samplers.SsnSamplerTest.java

@Test
public void testBogusFieldLimit() throws IOException {
    try {//  w ww  . j  a v  a 2s  .  com
        new SchemaSampler(
                Resources.asCharSource(Resources.getResource("schema020.json"), Charsets.UTF_8).read());
        fail("Should have failed due to invalid fields");
    } catch (JsonMappingException e) {
        Preconditions.checkState(e.getCause() instanceof IllegalArgumentException, "Wrong exception");
    }

}

From source file:com.mapr.synth.samplers.ZipSamplerTest.java

@Test
public void testBogusFieldLimit() throws IOException {
    try {//from  ww  w  .  ja  v  a 2 s.c  o m
        new SchemaSampler(
                Resources.asCharSource(Resources.getResource("schema018.json"), Charsets.UTF_8).read());
        fail("Should have failed due to invalid fields");
    } catch (JsonMappingException e) {
        Preconditions.checkState(e.getCause() instanceof IllegalArgumentException, "Wrong exception");
    }

}

From source file:com.addthis.codec.jackson.Jackson.java

public static IOException maybeUnwrapPath(String pathToSkip, IOException cause) {
    if ((pathToSkip != null) && (cause instanceof JsonMappingException)) {
        JsonMappingException mappingException = (JsonMappingException) cause;
        List<JsonMappingException.Reference> paths = mappingException.getPath();
        if (!paths.isEmpty()) {
            Iterator<String> pathIterator = dotSplitter.split(pathToSkip).iterator();
            Iterator<JsonMappingException.Reference> refIterator = paths.iterator();
            while (pathIterator.hasNext()) {
                String pathToSkipPart = pathIterator.next();
                if (!refIterator.hasNext()) {
                    return cause;
                }/*ww  w.j  av a 2 s  . c om*/
                String nextRefField = refIterator.next().getFieldName();
                if (!pathToSkipPart.equals(nextRefField)) {
                    return cause;
                }
            }
            JsonMappingException unwrapped = new JsonMappingException(rootMessage(mappingException),
                    mappingException.getLocation(), mappingException.getCause());
            if (refIterator.hasNext()) {
                List<JsonMappingException.Reference> remainingRefs = Lists.newArrayList(refIterator);
                for (JsonMappingException.Reference reference : Lists.reverse(remainingRefs)) {
                    unwrapped.prependPath(reference);
                }
            }
            return unwrapped;
        }
    }
    return cause;
}

From source file:com.wealdtech.jersey.providers.JsonMappingExceptionManager.java

@Override
public Response toResponse(final JsonMappingException exception) {
    LOGGER.info("JSON mapping exception", exception);
    ResponseBuilder builder = Response.status(Status.BAD_REQUEST)
            .entity(defaultJSON(Objects.firstNonNull(exception.getCause(), exception)))
            .type(MediaType.APPLICATION_JSON);
    return builder.build();
}

From source file:com.unboundid.scim2.common.PatchOpTestCase.java

/**
 * Test bad patch requests./*from  w w w  .  j a  va  2  s. c  om*/
 *
 * @throws IOException If an error occurs.
 * @throws ScimException If an error occurs.
 */
@Test
public void getTestBadPatch() throws IOException, ScimException {
    try {
        JsonUtils.getObjectReader().forType(PatchRequest.class)
                .readValue("{  \n" + "  \"schemas\":[  \n"
                        + "    \"urn:ietf:params:scim:api:messages:2.0:PatchOp\"\n" + "  ],\n"
                        + "  \"Operations\":[  \n" + "    {  \n" + "      \"op\":\"remove\",\n"
                        + "      \"path\":\"emails[type eq \\\"work\\\" and "
                        + "value ew \\\"example.com\\\"].too.deep\"\n" + "    }\n" + "  ]\n" + "}");
    } catch (JsonMappingException e) {
        assertEquals(((BadRequestException) e.getCause()).getScimError().getScimType(),
                BadRequestException.INVALID_PATH);
    }

    try {
        JsonUtils.getObjectReader().forType(PatchRequest.class)
                .readValue("{  \n" + "  \"schemas\":[  \n"
                        + "    \"urn:ietf:params:scim:api:messages:2.0:PatchOp\"\n" + "  ],\n"
                        + "  \"Operations\":[  \n" + "    {  \n" + "      \"op\":\"remove\",\n"
                        + "      \"path\":\"emails[type eq \\\"work\\\" and "
                        + "value ew \\\"example.com\\\"].sub[something eq 2]\"\n" + "    }\n" + "  ]\n" + "}");
    } catch (JsonMappingException e) {
        assertEquals(((BadRequestException) e.getCause()).getScimError().getScimType(),
                BadRequestException.INVALID_PATH);
    }

    try {
        JsonUtils.getObjectReader().forType(PatchRequest.class).readValue("{  \n" + "  \"schemas\":[  \n"
                + "    \"urn:ietf:params:scim:api:messages:2.0:PatchOp\"\n" + "  ],\n"
                + "  \"Operations\":[  \n" + "    {  \n" + "      \"op\":\"add\",\n"
                + "      \"path\":\"emails[type eq \\\"work\\\" and " + "value ew \\\"example.com\\\"],\"\n"
                + "      \"value\":\"value\"\n" + "    }\n" + "  ]\n" + "}");
    } catch (JsonMappingException e) {
        assertEquals(((BadRequestException) e.getCause()).getScimError().getScimType(),
                BadRequestException.INVALID_PATH);
    }
}