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

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

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind RuntimeJsonMappingException 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:feign.jackson.JacksonDecoder.java

@Override
public Object decode(Response response, Type type) throws IOException {
    if (response.body() == null) {
        return null;
    }/*from  w  w w . j  a va  2 s.  c o m*/
    InputStream inputStream = response.body().asInputStream();
    try {
        return mapper.readValue(inputStream, mapper.constructType(type));
    } catch (RuntimeJsonMappingException e) {
        if (e.getCause() != null && e.getCause() instanceof IOException) {
            throw IOException.class.cast(e.getCause());
        }
        throw e;
    }
}

From source file:cn.fintecher.print.web.util.JacksonDecoder.java

@Override
public Object decode(Response response, Type type) throws IOException {
    if (response.status() == 404)
        return Util.emptyValueOf(type);
    if (response.body() == null)
        return null;
    Reader reader = response.body().asReader();
    if (!reader.markSupported()) {
        reader = new BufferedReader(reader, 1);
    }/*from   w  w  w  .  j  a  va2  s  . com*/
    try {
        // Read the first byte to see if we have any data
        reader.mark(1);
        if (reader.read() == -1) {
            return null; // Eagerly returning null avoids "No content to map due to end-of-input"
        }
        reader.reset();
        return mapper.readValue(reader, mapper.constructType(type));
    } catch (RuntimeJsonMappingException e) {
        if (e.getCause() != null && e.getCause() instanceof IOException) {
            throw IOException.class.cast(e.getCause());
        }
        throw e;
    }
}

From source file:org.wso2.msf4j.client.codec.MSF4JJacksonDecoder.java

@Override
public Object decode(Response response, Type type) throws IOException, FeignException {
    if (response.body() == null) {
        return null;
    }/*from   ww w  . j  a  va 2  s . c o  m*/
    Reader reader = response.body().asReader();
    if (!reader.markSupported()) {
        reader = new BufferedReader(reader, 1);
    }
    try {
        // Read the first byte to see if we have any data
        reader.mark(1);
        if (reader.read() == -1) {
            return null; // Eagerly returning null avoids "No content to map due to end-of-input"
        }
        reader.reset();
        return mapper.readValue(reader, mapper.constructType(type));
    } catch (RuntimeJsonMappingException e) {
        Throwable cause = e.getCause();
        if (cause != null && cause instanceof IOException) {
            throw IOException.class.cast(cause);
        }
        throw e;
    }
}

From source file:io.instacount.client.decoders.AbstractInstacountDecoder.java

/**
 * Helper method to construct an instance of {@link Reader} for reading the JSON response from Instacount.
 *
 * @param response/*from  www . ja v  a  2  s  .  c om*/
 * @return
 * @throws IOException
 */
protected Optional<Reader> constructReader(final Response response) throws IOException {
    Preconditions.checkNotNull(response);
    Preconditions.checkNotNull(response.body());

    Reader reader = response.body().asReader();
    if (!reader.markSupported()) {
        reader = new BufferedReader(reader, 1);
    }
    try {
        // Read the first byte to see if we have any data
        reader.mark(1);
        if (reader.read() == -1) {
            // Eagerly returning null avoids "No content to map due to end-of-input"
            return Optional.absent();
        }
        reader.reset();
    } catch (RuntimeJsonMappingException e) {
        if (e.getCause() != null && e.getCause() instanceof IOException) {
            throw IOException.class.cast(e.getCause());
        }
        throw e;
    }

    return Optional.fromNullable(reader);
}