Skip to content
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

Add support for @BeanParam and Body/Entity #2

Open
EthanLozano opened this issue Jun 15, 2017 · 2 comments
Open

Add support for @BeanParam and Body/Entity #2

EthanLozano opened this issue Jun 15, 2017 · 2 comments

Comments

@EthanLozano
Copy link

This library fails with methods that have both a @BeanParam and a body. For instance:
ResultObject run(@BeanParam BeanObject bean, BodyObject body);

The current implementation relies on encoding the body as a bean parameter. So, the above method fails due to the JaxRsContract requiring a single body element.

First, there needs to be a Contract that handles @BeanParam as an http parameter. Second, I think the Contract needs to specify an indexToExpander. Third, I think the BeanParamTransformer's expand method needs to be implemented to be similar to the BeanParamEncoder (which seems to be used exclusively for body encoding).

@EthanLozano
Copy link
Author

Turns out that a parameter Expander simply turns an object into a String, so Expanders don't help in this situation

@EthanLozano
Copy link
Author

I changed this library to work for my use case. Specifically, I made a @BeanParam object parameter equivalent to a @QueryMap Map<String, Object> parameter.

  1. Bump the feign version to 8.17.0, which contains a @QueryMap annotation

  2. Fork the Contract.BaseContract so that it doesn't validate a @QueryMap as a Map

     //if (data.queryMapIndex() != null) {
     //    checkState(Map.class.isAssignableFrom(parameterTypes[data.queryMapIndex()]),
     //            "QueryMap parameter must be a Map: %s", parameterTypes[data.queryMapIndex()]);
     //}
    
  3. Fork the JAXRSContract to extend the forked BaseContract, and to classify @BeanParam as a @QueryMap:

         else if (annotationType == BeanParam.class) {
             data.queryMapIndex(paramIndex);
             isHttpParam = true;
         }
    
  4. Change the BeanParamMethodHandler to return a Map<String, Object> of the params rather than a EncoderContext

         Map<String, Object> params = transformer.transform(argv);
         argv[paramIndex] = params;
         return delegate.invoke(argv);
    
  5. Change the JAXRS2Profile so that it no longer uses a BeanParamEncoder

  6. Change the JAXRS2Profile to use the forked JAXRSContract

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant