caelum/vraptor — Issue #424: @Consumes("application/x-www-form-urlencoded") doesn't work
Author: celsodantas
Created: 2012-01-16 12:36:39+00:00
State: open

I'm trying to make a controller method accepts application/json and application/x-www-form-urlencoded mime type at the same time:

@Consumes (values={"application/json", "application/x-www-form-urlencoded"})

But it doesn't work. If I remove the @Consumes completely, it accepts the ""application/x-www-form-urlencoded" format, but if I add it, it just stops working.

But there is a workaround! Add this class to your project:

//
// It was a Lucas Cavalcanti sugestion!
//
@Deserializes("application/x-www-form-urlencoded")
public class FormDeserializer implements Deserializer {

private ParametersProvider provider;
private Localization localization;

public FormDeserializer(ParametersProvider provider, Localization localization) {
this.provider = provider;
this.localization = localization;
}

public Object[] deserialize(InputStream inputStream, ResourceMethod method) {
List errors = new ArrayList();
return provider.getParametersFor(method, errors, localization.getBundle());

}
}

And now using:

@Consumes (values={"application/json", "application/x-www-form-urlencoded"})

should work fine.