users@jersey.java.net

Re: Using JAXB for JSON and XML with one HTTP method

From: David Van Couvering <David.Vancouvering_at_Sun.COM>
Date: Tue, 07 Aug 2007 11:05:51 -0700

Very nice!

David

Paul Sandoz wrote:
> Hi,
>
> I just committed a fix for the latest build so one can do the following:
>
> @UriTemplate("/")
> public class MyResource {
> @HttpMethod
> @ProduceMime({"application/xml", "application/json"})
> public JAXBBean get() {
> JAXBBean j = ...
> return j;
> }
> }
>
> If there is no accept header or the accept is "*", "application/*" or
> "application/xml" then the JAXB bean will be serialized as XML. If the
> accept header is "application/json" then the JAXB bean will be
> serialized as JSON (as per the modifications made by Jakub to the JAXB
> element entity provider).
>
> Unit tests pass so it should work... :-)
>
> Paul.
>