Repository navigation
Interceptor decoder - #534
Conversation
|
Why don't we wait to see if more people want something like this in core. |
|
@spencergibb Cool! I just updated the description to reference headers rewriting ;) |
|
tons of votes on this one (relatively speaking) |
| import java.io.IOException; | ||
| import java.lang.reflect.Type; | ||
|
|
||
| public class InterceptorDecoder implements Decoder { |
There was a problem hiding this comment.
ResponseMappingDecoder? Add some javadoc since this is a public type, and tighten up with finals etc?
There was a problem hiding this comment.
ResponseMappingDecoder seems a good name for me, I can change it!
Also you're right about the final modifier to the properties and some javadoc, I'm on it ;)
| ```java | ||
| GitHub github = Feign.builder() | ||
| .decoder( | ||
| new InterceptorDecoder( |
There was a problem hiding this comment.
tempted to make this stuff private and only expose the builder..
Ex. mapAndDecode((response, type) -> myTransformingLogic(response, type), new GsonDecoder())
thoughts?
There was a problem hiding this comment.
It is ok for me! But for make this Decoder private (at least package private) I have to move it from the feign.codec package to the feignone... is that ok for you?
There was a problem hiding this comment.
it could be a static package protected member of feign
There was a problem hiding this comment.
fyi we'll be doing a release in a couple days
There was a problem hiding this comment.
thanks for be patient!
I'm not sure that I understand what do you want to say with "static package protected member of feign"...
make the ResponseMappingDecoder an inner class insied the feign.Feign abstract class?
There was a problem hiding this comment.
yep that's what I meant. The users don't need to know about this type.
|
can those voting mention what you want to use this for? |
# Conflicts: # core/src/test/java/feign/FeignTest.java
| /** | ||
| * Map function to apply to the response before decoding it. | ||
| */ | ||
| public interface ResponseMapper { |
There was a problem hiding this comment.
make this part a top-level type.
Also, please add an example in the javadoc.
ex.
<pre>{@code
// your compelling example here:
}</pre>
|
|
||
| ```java | ||
| GitHub github = Feign.builder() | ||
| .mapAndDecode((response, type) -> myTransformingLogic(response, type), new GsonDecoder()) |
There was a problem hiding this comment.
myTransformingLogic is coolio, but there's probably a better hint. Ex what made you want this in the first place? is there a concrete, but easy to understand example? Notably, the map happens before the decoding, so something like unwrapping a nested json envelope doesn't seem to be realistic.
Let's make this easy to understand!
ps.. leave out the github thing as their api is already nice :)
There was a problem hiding this comment.
I had 2 use cases for this, ciphered JSONS and JSONP responses...
I explained the second one because I think that could be more usual.
codefromthecrypt
left a comment
There was a problem hiding this comment.
made some comments to tighten up.. basically need to understand what the preprocessing will do for folks.
next, update CHANGES (which will be 9.5)
- Made ResponseMapper a top level type. - Example of usage for ResponseMapper.
Adds `Feign.Builder.mapAndDecode()` to allow response preprocessing before decoding it
Adds `Feign.Builder.mapAndDecode()` to allow response preprocessing before decoding it
Adds `Feign.Builder.mapAndDecode()` to allow response preprocessing before decoding it
Hi all!
I have an use case in which I have to interact with some HTTP API that is currently responding ciphered JSONs (I can't change this), so I need to first decipher that JSON before giving it to the Decoder (JacksonDecoder in my case).
To do this in a generic way I implemented an InterceptorDecoder that allows you to intercept the feign response before the desired decoder is called.
This also could be used to rewrite the response headers.
For example, okhttp allow to do that in a similar way: https://github.com/square/okhttp/wiki/Interceptors#rewriting-responses