Jersey does not know how to deserialize your bean from a plain text
request - you have to implement that logic yourself by writing your own
MessageBodyReader that takes a stream of plain text and constructs
FooBean from it. Then it will work as you expect.
Martin
On 18.3.2011 4:49, NBW wrote:
> 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
>