Return null (empty target object) if status code is 204#792
Conversation
| @Override | ||
| public Object decode(Response response, Type type) throws IOException { | ||
| if (response.status() == 404) | ||
| if (response.status() == 404 || response.status() == 204) |
There was a problem hiding this comment.
Sounds fair.
Could you just add a test for 204 as well?
There was a problem hiding this comment.
Should we do this globally or just in this decoder? @velo?
There was a problem hiding this comment.
Or better yet, we should inspect the body before sending it to the Decoder here:
feign/core/src/main/java/feign/SynchronousMethodHandler.java
Lines 162 to 170 in d7cc9b6
There was a problem hiding this comment.
I prefer a global way to handle it.
There was a problem hiding this comment.
Should we do this globally or just in this decoder?
@kdavisk6 we could, but that would break current API for all decoders...
If you think of a OptionalDecoder the result for a 204 or 404 is Optional.empty()
For a JAXB decoder null
For a List decoder may be Collections.emptyList() (which I currently use for a binary format decoder.
So, although I would like to see this in a single location, I don't think we can.
There was a problem hiding this comment.
Fair enough. Let's go with this for now and keep an eye out for other issues.
As mention in #791 JAXBDecoder should check also for status code 204 before trying to decode response body.