users@jersey.java.net

Re: [Jersey] Is it possible to consume FORM_URLENCODED and XML in same method?

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 25 Jun 2010 07:13:44 -0700

Hi Bo,

I would not recommend combining the two resource methods into one
method as they are consuming different types.

Both methods can occur on the same resource class as long as the
method names are different, you do not require two resource classes.

Paul.

On Jun 25, 2010, at 7:01 AM, Bo Xu wrote:

> For xml and json I know I can do this:
> @POST
> @Consumes({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
> @Produces("text/plain")
> public String post(Contact c)
> {
>
> return "got it";
> }
>
> @XmlRootElement(name="contact")
> @XmlAccessorType(XmlAccessType.FIELD)
> public class Contact {
> .......
> }
>
> For FORM_URLENCODED, I have to do it in another way:
> @POST
> @Consumes({MediaType.APPLICATION_ FORM_URLENCODED})
> public String post(@FormParam("identity_value") String identity,
> @FormParam("identity_type") String type,
> @FormParam("comment") String comment)
> {
>
> }
>
>
> how can I combine them together in one method? Otherwise I have to
> create 2 resource classes and each contains a post method?
>
> Thanks!
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>