Search in sources :

Example 1 with JSONObjectException

use of com.fasterxml.jackson.jr.ob.JSONObjectException in project feign by OpenFeign.

the class JacksonJrDecoder method decode.

@Override
public Object decode(Response response, Type type) throws IOException {
    Transformer transformer = findTransformer(response, type);
    if (response.body() == null) {
        return null;
    }
    Reader reader = response.body().asReader(response.charset());
    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 transformer.apply(mapper, reader);
    } catch (JSONObjectException e) {
        if (e.getCause() instanceof IOException) {
            throw (IOException) e.getCause();
        }
        throw e;
    }
}
Also used : BufferedReader(java.io.BufferedReader) Reader(java.io.Reader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) JSONObjectException(com.fasterxml.jackson.jr.ob.JSONObjectException)

Aggregations

JSONObjectException (com.fasterxml.jackson.jr.ob.JSONObjectException)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 Reader (java.io.Reader)1