Search in sources :

Example 1 with RuntimeJsonMappingException

use of com.fasterxml.jackson.databind.RuntimeJsonMappingException in project feign by OpenFeign.

the class JacksonDecoder method decode.

@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);
    }
    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 null;
        }
        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;
    }
}
Also used : BufferedReader(java.io.BufferedReader) BufferedReader(java.io.BufferedReader) Reader(java.io.Reader) IOException(java.io.IOException) RuntimeJsonMappingException(com.fasterxml.jackson.databind.RuntimeJsonMappingException)

Aggregations

RuntimeJsonMappingException (com.fasterxml.jackson.databind.RuntimeJsonMappingException)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 Reader (java.io.Reader)1