Search in sources :

Example 1 with InvalidDefinitionException

use of com.fasterxml.jackson.databind.exc.InvalidDefinitionException in project jackson-databind by FasterXML.

the class SerializerProvider method reportBadDefinition.

/**
     * @since 2.9
     */
public <T> T reportBadDefinition(JavaType type, String msg, Throwable cause) throws JsonMappingException {
    InvalidDefinitionException e = InvalidDefinitionException.from(getGenerator(), msg, type);
    e.initCause(cause);
    throw e;
}
Also used : InvalidDefinitionException(com.fasterxml.jackson.databind.exc.InvalidDefinitionException)

Example 2 with InvalidDefinitionException

use of com.fasterxml.jackson.databind.exc.InvalidDefinitionException in project jackson-databind by FasterXML.

the class SerializerProvider method reportBadDefinition.

/**
     * @since 2.9
     */
public <T> T reportBadDefinition(Class<?> raw, String msg, Throwable cause) throws JsonMappingException {
    InvalidDefinitionException e = InvalidDefinitionException.from(getGenerator(), msg, constructType(raw));
    e.initCause(cause);
    throw e;
}
Also used : InvalidDefinitionException(com.fasterxml.jackson.databind.exc.InvalidDefinitionException)

Example 3 with InvalidDefinitionException

use of com.fasterxml.jackson.databind.exc.InvalidDefinitionException in project dropwizard by dropwizard.

the class JsonProcessingExceptionMapper method toResponse.

@Override
public Response toResponse(JsonProcessingException exception) {
    /*
         * If the error is in the JSON generation or an invalid definition, it's a server error.
         */
    if (exception instanceof JsonGenerationException || exception instanceof InvalidDefinitionException) {
        // LoggingExceptionMapper will log exception
        return super.toResponse(exception);
    }
    /*
         * Otherwise, it's those pesky users.
         */
    logger.debug("Unable to process JSON", exception);
    final String message = exception.getOriginalMessage();
    final ErrorMessage errorMessage = new ErrorMessage(Response.Status.BAD_REQUEST.getStatusCode(), "Unable to process JSON", showDetails ? message : null);
    return Response.status(Response.Status.BAD_REQUEST).type(MediaType.APPLICATION_JSON_TYPE).entity(errorMessage).build();
}
Also used : InvalidDefinitionException(com.fasterxml.jackson.databind.exc.InvalidDefinitionException) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) ErrorMessage(io.dropwizard.jersey.errors.ErrorMessage)

Example 4 with InvalidDefinitionException

use of com.fasterxml.jackson.databind.exc.InvalidDefinitionException in project jackson-databind by FasterXML.

the class DeserializationContext method instantiationException.

/**
     * Helper method for constructing instantiation exception for specified type,
     * to indicate problem with physically constructing instance of
     * specified class (missing constructor, exception from constructor)
     *<p>
     * Note that most of the time this method should NOT be called; instead,
     * {@link #handleInstantiationProblem} should be called which will call this method
     * if necessary.
     */
public JsonMappingException instantiationException(Class<?> instClass, Throwable cause) {
    // Most likely problem with Creator definition, right?
    JavaType type = constructType(instClass);
    String msg = String.format("Can not construct instance of %s, problem: %s", ClassUtil.nameOf(instClass), cause.getMessage());
    InvalidDefinitionException e = InvalidDefinitionException.from(_parser, msg, type);
    e.initCause(cause);
    return e;
}
Also used : InvalidDefinitionException(com.fasterxml.jackson.databind.exc.InvalidDefinitionException)

Aggregations

InvalidDefinitionException (com.fasterxml.jackson.databind.exc.InvalidDefinitionException)4 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)1 ErrorMessage (io.dropwizard.jersey.errors.ErrorMessage)1