New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Object Query with GET request #620
Conversation
I'm not affiliated to Feign but it would be nice to have some unit tests to test this feature? |
yep, I will add some unit tests to the pull request.
Thanks,
Daniel
…________________________________
From: Guillaume <notifications@github.com>
Sent: Tuesday, January 2, 2018 10:47:01 PM
To: OpenFeign/feign
Cc: Daniel Wu; Author
Subject: Re: [OpenFeign/feign] Support Object Query with GET request (#620)
I'm not affiliated to Feign but it would be nice to have some unit tests to test this feature?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub<#620 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AAfZcU1Ls7xac0KlXxqIWs1MIzlP093Bks5tGkFlgaJpZM4RO_f7>.
|
Too busy recently, will add unit tests later, sorry |
unit test added, please review it, thanks! |
good job ! +1 @DanielYWoo |
On the whole I think this looks like a pretty cool bit of functionality. I have one main concern - I don't think this is documented well at all. I would want to see some very clear documentation that indicates some of the assumptions that this code makes:
I am unfamiliar with the format Would love to see some unit tests with edge cases for the ObjectEncoder in addition to the integration style tests you've got on the Feign class. Finally, I would recommend that you read https://github.com/OpenFeign/feign/blob/master/CONTRIBUTING.md and format your PR accordingly. For example, I don't see any licensing information on new files. |
With regards to the
You can use the |
Why not also allow the annotations on member variables? (kinda like the jackson library) |
This is an excellent change. I would personally like to see it included, and even expanded upon (maybe allowing path param annotations as well, and definitely allowing annotations on member variables rather than just getter methods). |
If you want that, why not use https://cloud.spring.io/spring-cloud-netflix/multi/multi_spring-cloud-feign.html This adds support for the Spring MVC annotations include Path, Request, and other variables. It's a complete implementation of what you are asking for, but it does require Spring If you would like to discuss this more, let's move that to the issue and not this PR. Let's keep this thread clear so @DanielYWoo can see the PR feedback. |
@benmanbs I will change accordingly later, I am too busy recently, sorry about the late response. |
@kdavisk6 Yes, you spotted a bug about the java bean convention. I will fix it and add more unit tests. And I probably will make the annotation only on member variables instead of getters, to be friendly to lombok. And I will do some benchmark to see how much performance can be improved with javassist by avoiding reflections on each call. If the performance improvements is worthy of it, I probably make javassist as an optional dependency. |
@DanielYWoo with regards to Spring, I was making a reference to something that has already been implemented showing what you all wanted. If your desire is to add this to Feign proper, I think a more elegant solution is to add an additional |
@kdavisk6 oohhh... That's nice. I hadn't noticed that before. The jax-rs contract seems like a good place to start: https://github.com/OpenFeign/feign/blob/master/jaxrs/src/main/java/feign/jaxrs/JAXRSContract.java Thanks for the tip. As regards Spring, I agree with @DanielYWoo that it isn't for libraries. Spring is way too much overkill for a simple client library that might be used in any context. We do have some spring services here, so it must be usable in such a context, but not everything we have needs or wants all of that complexity, so it shouldn't pull in spring as a dependency just to use (what should be) a simple client library. |
@kdavisk6 looking at the This doesn't look like it would work. Am I missing something? Do you have any examples that you could point us to where a single interface method argument can be used to support multiple query parameters? |
Again, I'll go back to Spring In their code, they created The Using Spring as an example, one way to make this work in core Feign would be expand the I'm learning too as I review this PR. The more I look into it, the more @DanielYWoo's approach is pretty close. I still think moving away from reflection is a better idea, and @DanielYWoo has already agreed. This is a great start. |
@kdavisk6 that Spring class doesn't do what this pull request is trying to do, it can actually generate everything it needs with the method signature (since each thing that it is handling represents a single thing), so it can use a custom I don't believe the |
Understood. In that case, I still recommend that |
I think that the cleaner solution would be to modify the default |
@DanielYWoo Would #667 work for you? It should allow you to create your QueryObject annotation and QueryObjectEncoder class locally and include it via: @CustomParam(encoder = QueryObjectEncoder.class) MyQueryObject myQueryObject That PR allows your custom encoder to modify query params (as your class is doing) or headers (we needed to use param context in generating our auth headers as well) or whatever you need (as with custom encoders and interceptors, use at your own risk since you can totally mangle everything in the template if you screw something up). I'd like to find something that would work for you, me, #636 and anyone else who needs something similar (this might even solve #601 if it doesn't need to be run again on every retry). |
@rage-shadowman I am fine with #667, it's more flexible, but I hope you can include QueryParams into your change, because this annotation will solve 95% of our real world problems so it should just work out of box. |
@DanielYWoo what do you mean "QueryParams"? I updated the PR based on comments to just use the existing I would have like to have done it with annotations similar to the way you define JSON serialization in a Jackson annotated POJO, but the discussion went another way, and I think I can make that work for me. |
With support added for |
@kdavisk6 Does QueryMap in 9.7 support POJO other than Map<Object, Object>? |
Yes, you can provide your own |
@rage-shadowman It works but you will have to write a custom encoder for each query object class. This is not what I want. What I want is a single generic encoder to use the annotation info in your query object class. |
@DanielYWoo, I think you may have misunderstood the documentation. public class FormBean {
private String name;
private String favoriteIceCream;
} public interface IceCreamService {
@RequestLine("POST /favorite")
public void favoriteIceCream(@QueryMap FormBean favoriteForm)
} will expand to If you need to customize this processing, you can provide an optional |
@DanielYWoo what are your thoughts on this? Are there any additional use cases you have where a |
@kdavisk6 I think @rage-shadowman 's solution is more flexible but a little overkill, and you will have to write a whole lot of decoders, the QueryMap annotation is just fine for me. I think we can close this ticket now. Thank you! |
Let's say you have two mandatory parameters and an optional parameters, you will have to implement it this way:
If you have more optional parameters you will have to implement a lot of overloaded methods, otherwise you can only implement a method with a lot of parameters and when it is called, you have to pass in a bunch of null values like this:
This is very ugly, if we have object parameter we can do this: first, use a constructor to pass in all mandatory parameters, then use setters to set the optional parameters like this:
Relaated to #520