users@jersey.java.net

Re: [Jersey] Sending xml to Jersey

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 12 Feb 2009 16:36:24 +0100

On Feb 12, 2009, at 4:19 PM, paradisonoir wrote:

>
> Hi Paul,
>
>
> Paul Sandoz wrote:
>>
>>
>>> 1) Does this resource.accept(MediaType.APPLICATION_XML)
>>> automatically
>>> convert/transform our request to XML?
>>
>> No. You need to provide a correct Java type is capable of being
>> unmarshalled from XML.
>>
>
>
> so in my case, myObject, which is what I am going to send to my
> server-side
> jersey handler, is an instance of a JAXB object (automatically
> generated
> from an xml schema , containing all getters/setters of its xml
> elements).
> So, I can use my myObject in here to send a request in
> APPLICATION_XML type.
>
> Builder builder = resource.accept(MediaType.APPLICATION_XML);
> builder.entity(myObject);
>

Yes. Plus i recommend setting the type of the entity as well.

   builder.entity(myObject, MediaType.APPLICATION_XML);

Jersey will attempt to derive a default media type if one is not
declared, but it is good to be specific.

Paul.

>
> --
> View this message in context: http://n2.nabble.com/Sending-xml-to-Jersey-tp2286744p2315399.html
> Sent from the Jersey mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>