Example usage for com.fasterxml.jackson.databind.exc InvalidFormatException getMessage

List of usage examples for com.fasterxml.jackson.databind.exc InvalidFormatException getMessage

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.exc InvalidFormatException getMessage.

Prototype

public String getMessage() 

Source Link

Usage

From source file:fr.ortolang.diffusion.api.mapper.InvalidFormatExceptionMapper.java

@Override
public Response toResponse(InvalidFormatException ex) {
    return Response.status(Status.NOT_FOUND).entity("Metadata content is not valid: " + ex.getMessage())
            .type("text/plain").build();
}

From source file:org.primeframework.mvc.content.json.JacksonContentHandler.java

@Override
public void handle() throws IOException {
    ActionInvocation current = store.getCurrent();
    Object action = current.action;
    if (action == null) {
        return;//from  w  w  w  . j  a  va 2 s.  c  om
    }

    ActionConfiguration config = current.configuration;
    if (!config.additionalConfiguration.containsKey(JacksonActionConfiguration.class)) {
        return;
    }

    int contentLength = request.getContentLength();
    if (contentLength == 0) {
        return;
    }

    // Process JSON and set into the object
    JacksonActionConfiguration jacksonConfiguration = (JacksonActionConfiguration) config.additionalConfiguration
            .get(JacksonActionConfiguration.class);
    if (jacksonConfiguration.requestMember != null) {
        try {
            Object jsonObject;
            if (logger.isDebugEnabled()) {
                final String req = IOUtils.toString(request.getInputStream(), "UTF-8");
                logger.debug("Request: (" + request.getMethod() + " " + request.getRequestURI() + ") " + req);
                jsonObject = objectMapper.reader(jacksonConfiguration.requestMemberType).readValue(req);
            } else {
                jsonObject = objectMapper.reader(jacksonConfiguration.requestMemberType)
                        .readValue(request.getInputStream());
            }

            expressionEvaluator.setValue(jacksonConfiguration.requestMember, action, jsonObject);
        } catch (InvalidFormatException e) {
            logger.debug("Error parsing JSON request", e);
            addFieldError(e);
            throw new ValidationException(e);
        } catch (UnrecognizedPropertyException e) {
            logger.debug("Error parsing JSON request", e);
            String field = buildField(e);
            messageStore.add(new SimpleMessage(MessageType.ERROR, "[unrecognizedProperty]",
                    messageProvider.getMessage("[unrecognizedProperty]", field, e.getMessage())));
            throw new ValidationException(e);
        } catch (JsonMappingException e) {
            logger.debug("Error parsing JSON request", e);

            if (!(e.getCause() instanceof JsonParseException)) {
                addFieldError(e);
            } else {
                messageStore.add(new SimpleMessage(MessageType.ERROR, "[couldNotParseJSON]",
                        messageProvider.getMessage("[couldNotParseJSON]", e.getMessage())));
            }
            throw new ValidationException(e);
        } catch (JsonProcessingException e) {
            logger.debug("Error parsing JSON request", e);
            messageStore.add(new SimpleMessage(MessageType.ERROR, "[couldNotParseJSON]",
                    messageProvider.getMessage("[couldNotParseJSON]", e.getMessage())));
            throw new ValidationException(e);
        }
    }
}