MCPcopy Index your code
hub / github.com/OpenFeign/feign / decode

Method decode

json/src/main/java/feign/json/JsonDecoder.java:58–86  ·  view source on GitHub ↗
(Response response, Type type)

Source from the content-addressed store, hash-verified

56public class JsonDecoder implements Decoder, feign.codec.JsonDecoder {
57
58 @Override
59 public Object decode(Response response, Type type) throws IOException, DecodeException {
60 if (response.status() == 404 || response.status() == 204)
61 if (Map.class.equals(type)) return null;
62 else if (JSONObject.class.isAssignableFrom((Class<?>) type)) return new JSONObject();
63 else if (JSONArray.class.isAssignableFrom((Class<?>) type)) return new JSONArray();
64 else if (String.class.equals(type)) return null;
65 else
66 throw new DecodeException(
67 response.status(),
68 format("%s is not a type supported by this decoder.", type),
69 response.request());
70 if (response.body() == null) return null;
71 try (Reader reader = response.body().asReader(response.charset())) {
72 Reader bodyReader = (reader.markSupported()) ? reader : new BufferedReader(reader);
73 bodyReader.mark(1);
74 if (bodyReader.read() == -1) {
75 return null; // Empty body
76 }
77 bodyReader.reset();
78 return decodeBody(response, type, bodyReader);
79 } catch (JSONException jsonException) {
80 if (jsonException.getCause() != null && jsonException.getCause() instanceof IOException) {
81 throw (IOException) jsonException.getCause();
82 }
83 throw new DecodeException(
84 response.status(), jsonException.getMessage(), response.request(), jsonException);
85 }
86 }
87
88 private Object decodeBody(Response response, Type type, Reader reader) throws IOException {
89 if (String.class.equals(type)) return Util.toString(reader);

Callers

nothing calls this directly

Implementers 6

MoshiDecodermoshi/src/main/java/feign/moshi/MoshiD
JacksonJrDecoderjackson-jr/src/main/java/feign/jackson
Jackson3Decoderjackson3/src/main/java/feign/jackson3/
Fastjson2Decoderfastjson2/src/main/java/feign/fastjson
JacksonDecoderjackson/src/main/java/feign/jackson/Ja
GsonDecodergson/src/main/java/feign/gson/GsonDeco

Calls 12

decodeBodyMethod · 0.95
formatMethod · 0.80
bodyMethod · 0.65
asReaderMethod · 0.65
statusMethod · 0.45
equalsMethod · 0.45
requestMethod · 0.45
charsetMethod · 0.45
markMethod · 0.45
readMethod · 0.45
resetMethod · 0.45
getMessageMethod · 0.45

Tested by

no test coverage detected