@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) { 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; } } }
@Override public Object decode(Response response, Type type) throws IOException, FeignException { 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) { 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; } } }