2626
2727/**
2828 * Decodes an HTTP response into a single object of the given {@code Type}. Invoked when
29- * {@link Response#status()} is in the 2xx range. Like
30- * {@code javax.websocket.Decoder}, except that the decode method is passed the
31- * generic type of the target.
32- *
33- * <p>
29+ * {@link Response#status()} is in the 2xx range and the return type is neither {@code void} nor {@code Response}.
30+ * <p/>
31+ * <p/>
3432 * Example Implementation:<br>
3533 * <p/>
3634 * <pre>
3735 * public class GsonDecoder implements Decoder {
38- * private final Gson gson;
39- *
40- * public GsonDecoder(Gson gson) {
41- * this.gson = gson;
42- * }
36+ * private final Gson gson = new Gson();
4337 *
4438 * @Override
4539 * public Object decode(Response response, Type type) throws IOException {
@@ -62,7 +56,7 @@ public interface Decoder {
6256 * If you need to wrap exceptions, please do so via {@link DecodeException}.
6357 *
6458 * @param response the response to decode
65- * @param type Target object type.
59+ * @param type Target object type.
6660 * @return instance of {@code type}
6761 * @throws IOException will be propagated safely to the caller.
6862 * @throws DecodeException when decoding failed due to a checked exception besides IOException.
@@ -71,19 +65,12 @@ public interface Decoder {
7165 Object decode (Response response , Type type ) throws IOException , DecodeException , FeignException ;
7266
7367 /**
74- * Default implementation of {@code Decoder} that supports {@code void}, {@code Response}, and {@code String}
75- * signatures.
68+ * Default implementation of {@code Decoder} that supports {@code String} signatures.
7669 */
7770 public class Default implements Decoder {
7871 @ Override
7972 public Object decode (Response response , Type type ) throws IOException {
80- if (Response .class .equals (type )) {
81- String bodyString = null ;
82- if (response .body () != null ) {
83- bodyString = Util .toString (response .body ().asReader ());
84- }
85- return Response .create (response .status (), response .reason (), response .headers (), bodyString );
86- } else if (void .class .equals (type ) || response .body () == null ) {
73+ if (response .body () == null ) {
8774 return null ;
8875 } else if (String .class .equals (type )) {
8976 return Util .toString (response .body ().asReader ());
0 commit comments