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

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

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.exc InvalidFormatException 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: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  ww  w .jav  a2 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);
        }
    }
}