Hi Peter,
I have just commited first working version of json support into repository.
You should be able to do things like
@HttpMethod("GET")
@ProduceMime("application/json")
public JAXBObject getTheObjectAsJson() {
return getTheJAXBObject(); // returns a @XmlRootElement annotated object
}
@HttpMethod("GET")
@ProduceMime("application/xml")
public JAXBObject getTheObjectAsXml() {
return TheJAXBObject(); // note that the same object is used here
}
If a client asks for "application/json" mime type (by using
"Accept: application/json" header), a JSON representation (in badgerfish [1] notation)
of the JAXB object is returned.
Similarly, the client can put/post json data to a service:
@HttpMethod("PUT")
@ConsumeMime("application/json")
public Response putTheObjectAsJson(JAXBObject obj) {
setJAXBObject(obj);
return Response.Builder.noContent().build();
}
@HttpMethod("PUT")
@ConsumeMime("application/xml")
public Response putTheObjectAsXml(JAXBObject obj) {
setJAXBObject(obj);
return Response.Builder.noContent().build();
}
In the future, you will not need to have two different methods (not implemented yet)
for different mime types.
At the moment, jettison [2] library is used for the XML<->JSON translation and this will be rewritten
as well, but you can already try, how the JSON support will look like.
~Jakub
[1]
http://badgerfish.ning.com/
[2]
http://jettison.codehaus.org/
On Wed, Jul 11, 2007 at 09:29:50AM +0200, Paul Sandoz wrote:
> Hi Peter,
>
> Jakub is working on the JSON support for JAXB so he can chime in with
> more specific details.
>
>
> We will aim to do the following:
>
> public class MyResource {
> @ProduceMime("application/xml, application/json")
> JAXBObject getMyStuff() { ... }
> }
>
> The JAXB entity provider will work out, from the selected content type
> (to be implemented), to use XML or JSON (same should be the case when
> using JAXB as the entity for a request to a PUT/POST).
>
> Paul.
>
> Peter Liu wrote:
> >Hi,
> >
> >I would like to start a discussion on adding support for JSON in jersey.
> >On my wish list for this feature is the ability to work off existing jaxb-
> >annotated classes either directly or via some wrapper.
> >
> >Thanks.
> >
> >Peter
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: dev-unsubscribe_at_jersey.dev.java.net
> >For additional commands, e-mail: dev-help_at_jersey.dev.java.net
> >
>
> --
> | ? + ? = To question
> ----------------\
> Paul Sandoz
> x38109
> +33-4-76188109
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: dev-help_at_jersey.dev.java.net
>