-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Form-encoded parameters #259
Comments
if you have a method which has no We can teach the default encoder to do multipart form and/or there could be a wrapper. The wrapper could be used to mix in form encoding with gson, for example. class FormAwareEncoder implements Encoder {
private final Encoder delegate;
public void encode(Object object, Type bodyType, RequestTemplate template) {
if (bodyType.equals(Types.MAP_STRING_WILDCARD)) {
// something like https://github.com/square/okhttp/blob/master/okhttp/src/main/java/com/squareup/okhttp/FormEncodingBuilder.java or this, but not using guava https://github.com/jclouds/jclouds/blob/master/core/src/main/java/org/jclouds/io/payloads/MultipartForm.java
} else {
delegate.encode(object, bodyType, template);
}
}
} cc @jmnarloch |
Hi, yeah, that was the way I understood it too.
|
Thanks for posting how you did it!
|
Hi, I'm currently facing the same issues with multipart requests.. I created a sample project that allows multipart form submission through Feign, but it uses a really ugly approach to detect the form request ( package feign;
public abstract class AbstractFormEncoder implements Encoder {
private final Encoder delegate;
public AbstractFormEncoder(Encoder delegate) {
this.delegate = delegate;
}
@Override
public final void encode(Object object, Type bodyType, RequestTemplate template) {
if (bodyType.equals(Types.MAP_STRING_WILDCARD)) {
formEncode(object, bodyType, template);
} else {
delegate.encode(object, bodyType, template);
}
}
public abstract void formEncode(Object object, Type bodyType, RequestTemplate template);
} @adriancole you already proposed this a few posts ago.. what do you think about this? |
kindof swamped to think about a form encoder right now, but maybe I can help make the hack less ugly. Something like this should be less gnarly. Ex I don't think you need to manually construct the type.. then you can do equals on it directly. class Foo {
static final Map<String, ?> MAP_STRING_WILDCARD = null;
final Type formType;
Foo(){
this.formType = getClass().getField("MAP_STRING_WILDCARD").getGenericType()
} |
@adriancole I tried this approach and it seems to work (but i had to use |
Which detail are you referring to when raising a concern about knowledge of
internals?
|
Ok, I'll try to clarify a bit more. At some point in |
Oh OK. So the map wildcard type is actually documented on the Encoder for
use in forms so I wouldn't call it internal or that you need to peek inside
to figure out this.
It doesn't include instructions of how to construct the type reference, and
neither does feign provide a type reference api (like guava, Jackson, gson,
moshi etc do). Probably lack of explanation on this is a problem.
Ex not everyone will have a type library handy, and then peek inside feign
and see it has an internal one then wonder as you have.
I think I would rather move the constant type to Encoder and make it
public. I can revise the javadoc with a link to it there, too.
Hope this helps and thanks for explaining.
|
Thank you. A public reference to |
Before, instructions around form encoding were incomplete, particularly around how to get a hold of a `Map<String, ?>` type. This exposes `Encoder.MAP_STRING_WILDCARD` to make form encoding easier. Closes #259
Before, instructions around form encoding were incomplete, particularly around how to get a hold of a `Map<String, ?>` type. This exposes `Encoder.MAP_STRING_WILDCARD` to make form encoding easier. Closes #259
@adriancole How would I then use feign to upload multiple files? I am still getting NullPointerException at isUserPojo What was the use of exposing the MAP_STRING_WILDCARD? @pcan How do we make use of this change? Is there any sample code? |
Hi,
new to Feign here. Got basic GET to work fine, but trying to make a POST with form-encoded parameters work. I have a basic interface:
Judging from the code, having params which does not match {} fields in URL, expands them as "formParams" which then makes use of BuildFormEncodedTemplateFromArgs to transform them into a LinkedHashMap.
But, using the default encoder for this, I get
feign.codec.EncodeException: class java.util.LinkedHashMap is not a type supported by this encoder.
, and I cannot seem to find any other encoder suitable for this.Am I missing something, or is this a non-complete feature?
Thanks
The text was updated successfully, but these errors were encountered: