public interface Decoder
type
. Invoked when
Response.status()
is in the 2xx range and the return type is neither void
nor
Response
.
Example Implementation:public class GsonDecoder implements Decoder { private final Gson gson = new Gson(); @Override public Object decode(Response response, Type type) throws IOException { try { return gson.fromJson(response.body().asReader(), type); } catch (JsonIOException e) { if (e.getCause() != null && e.getCause() instanceof IOException) { throw IOException.class.cast(e.getCause()); } throw e; } } }
type
parameter will correspond to the
generic return type
of an
interface
processed by Feign.newInstance(feign.Target)
.
When writing your implementation of Decoder, ensure you also test parameterized types such as
List<Foo>
. Decoder
s get wrapped in a
DecodeException
unless they are a subclass of FeignException
already, and unless
the client was configured with Feign.Builder#dismiss404()
.Modifier and Type | Interface and Description |
---|---|
static class |
Decoder.Default
Default implementation of
Decoder . |
Modifier and Type | Method and Description |
---|---|
Object |
decode(Response response,
Type type)
Decodes an http response into an object corresponding to its
generic return type . |
Object decode(Response response, Type type) throws IOException, DecodeException, FeignException
generic return type
. If you need to
wrap exceptions, please do so via DecodeException
.response
- the response to decodetype
- generic return type
of the
method corresponding to this response
.type
IOException
- will be propagated safely to the caller.DecodeException
- when decoding failed due to a checked exception besides IOException.FeignException
- when decoding succeeds, but conveys the operation failed.Copyright © 2012–2022 OpenFeign. All rights reserved.