users@jersey.java.net

[Jersey] Question about consuming TEXT_PLAN and JSON via POST

From: NBW <emailnbw_at_gmail.com>
Date: Thu, 17 Mar 2011 23:49:08 -0400

It doesn't look like Jersey supports consuming both JSON and TEXT_PLAIN at
the same resource out of the box but perhaps I am missing something. I have
Jackson POJO support configured. So for example:

@POST
@Consumes({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN})
@Produces(MediaType.APPLICATION_JSON)
public Response test1(@FormParam("foo") String foo, FooBean fooBeanJsonDO) {
    ...
}

public FooBean {
    public String foo;
}

When I mix @FormParam and the bean and try to POST JSON I get an
IllegalStateException: The @FormParam is utilized when the content type of
the request is not application/x-www-form-urlencoded.
If I remove the @FormParam and simply leave the bean and POST JSON it works.
However, then I try to POST form data it pukes. If I remove the bean and
leave the @FormParam it works when I POST form data but pukes when I POST
JSON.

I suppose I could break this into two resources, one consuming JSON and one
consuming FormData but I'd rather not - seems like it defeats the purpose. I
would think I should simply be able to have my bean be the method parameter
and Jersey would try to unmarshall the data from the consumed type(s) into
it. eg.

@POST
@Consumes({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN})
@Produces(MediaType.APPLICATION_JSON)
public Response test1(FooBean fooBeanJsonDO) {
    ...
}

Also, where can I find javadoc on com.sun.jersey.core.impl.* ?

Thanks,

-Noah