JAX-RS and JSon

9 messages Options
Embed this post
Permalink
Fabio Mancinelli

JAX-RS and JSon

Reply Threaded More More options
Print post
Permalink
Dear all,

I am successfully using restlet JAX-RS but I noticed that JSON is supported out of the box when I return something from a @GET annotated method but not when I send some JSON to a @PUT annotated method (wrt the same Java types, of course)

What I mean is that the system is capable of serializing from JAXB to JSON but not the vice-versa. (I got 415 errors when doing PUTs)

Is it normal or am I doing something wrong?

Thanks,
Fabio

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=7458&dsMessageId=1963895
StephanKoo

Re: JAX-RS and JSon

Reply Threaded More More options
Print post
Permalink
Hi Fabio,

do you have a special MessageWriter for serializing JAXB annotated
objects? If not (AFAIK ...), the JAX-RS extension uses the JSON
capabilities of Restlet, and there it is easier to serialize than to
deserialize. So I've only implemented the deserialization from every
class. As a workaround for deserialisation you could require type
JSONObject as entity type in your method and work with JSONObjects, and
perhaps copy from it.
I'm open for contribution here ...

best regards
   Stephan

Fabio Mancinelli schrieb:

> Dear all,
>
> I am successfully using restlet JAX-RS but I noticed that JSON is supported out of the box when I return something from a @GET annotated method but not when I send some JSON to a @PUT annotated method (wrt the same Java types, of course)
>
> What I mean is that the system is capable of serializing from JAXB to JSON but not the vice-versa. (I got 415 errors when doing PUTs)
>
> Is it normal or am I doing something wrong?
>
> Thanks,
> Fabio

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=7458&dsMessageId=1963982
jlouvel

RE: JAX-RS and JSon

Reply Threaded More More options
Print post
Permalink
Hi guys,

With the new XStream extension recently added to SVN trunk we could very
easily support both serialization and de-serialization in a transparent way,
for both JSON and XML. It works with the new resource API but could very
easily be ported to our JAX-RS extension!
 
Best regards,
Jerome Louvel
--
Restlet ~ Founder and Lead developer ~ http://www.restlet.org
Noelios Technologies ~ Co-founder ~ http://www.noelios.com
 

-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]]
Envoyé : mardi 28 avril 2009 16:16
À : [hidden email]
Objet : Re: JAX-RS and JSon

Hi Fabio,

do you have a special MessageWriter for serializing JAXB annotated objects?
If not (AFAIK ...), the JAX-RS extension uses the JSON capabilities of
Restlet, and there it is easier to serialize than to deserialize. So I've
only implemented the deserialization from every class. As a workaround for
deserialisation you could require type JSONObject as entity type in your
method and work with JSONObjects, and perhaps copy from it.
I'm open for contribution here ...

best regards
   Stephan

Fabio Mancinelli schrieb:

> Dear all,
>
> I am successfully using restlet JAX-RS but I noticed that JSON is
> supported out of the box when I return something from a @GET annotated
> method but not when I send some JSON to a @PUT annotated method (wrt
> the same Java types, of course)
>
> What I mean is that the system is capable of serializing from JAXB to
> JSON but not the vice-versa. (I got 415 errors when doing PUTs)
>
> Is it normal or am I doing something wrong?
>
> Thanks,
> Fabio

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=7458&dsMessageId=19639
82

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=7458&dsMessageId=1964393
webpost

RE: JAX-RS and JSon

Reply Threaded More More options
Print post
Permalink
Hey guys, where are we on this?  I am dealing with the same issue.  I am using the extjs javascript framework, and heavy on the JSON.  So I would love to be able to POST/PUT Json.

Thanks,
Micky

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=7458&dsMessageId=2399456
jlouvel

RE: JAX-RS and JSon

Reply Threaded More More options
Print post
Permalink
Hi Micky,

In 2.0 M5, a new JAXB converter was contributed (related to Restlet's
Converter Service). It should be automatically leveraged by the JAX-RS
extension if the org.restlet.ext.jaxb JAR is in the classpath. You might
also choose to leverage XStream support for JSON.

Let us know exactly what you want to achieve. A small illustrative
application would be useful for debugging if needed.

Best regards,
Jerome Louvel
--
Restlet ~ Founder and Lead developer ~ http://www.restlet.org
Noelios Technologies ~ Co-founder ~ http://www.noelios.com


-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]]
Envoyé : jeudi 24 septembre 2009 18:50
À : [hidden email]
Objet : RE: JAX-RS and JSon

Hey guys, where are we on this?  I am dealing with the same issue.  I am
using the extjs javascript framework, and heavy on the JSON.  So I would
love to be able to POST/PUT Json.

Thanks,
Micky

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=7458&dsMessageId=23994
56

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=7458&dsMessageId=2401611
webpost

RE: JAX-RS and JSon

Reply Threaded More More options
Print post
Permalink
Guys,
  We are back on this and still fighting with it.  Running a new build of restlet and trying to post json data back to a resource.
 It will accept and process xml just fine but trying to post application/json always gets back a http 415 return code.  These are the libraries we have in the sample code:

org.restlet.ext.jaxb.jar   org.restlet.ext.xml.jar
org.json_2.0
org.restlet.ext.jaxrs.jar
org.restlet.jar

Also attached is jax-rs resource file and the json that we are trying to POST.

Tried using the xstream library but the json produced is very different from the normal json and will not work with our browser code.

Any thoughts are greatly appreciated.

 Thanks
    Chris

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=7458&dsMessageId=2412333
jlouvel

RE: JAX-RS and JSon

Reply Threaded More More options
Print post
Permalink
Hi Chris,

To get a clean JSON support, you need to add the org.restlet.ext.xstream.jar
and its dependencies to the classpath like the XStream and Jettison JARs.

Best regards,
Jerome Louvel
--
Restlet ~ Founder and Lead developer ~ http://www.restlet.org
Noelios Technologies ~ Co-founder ~ http://www.noelios.com



-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]]
Envoyé : jeudi 29 octobre 2009 01:07
À : [hidden email]
Objet : RE: JAX-RS and JSon

Guys,
  We are back on this and still fighting with it.  Running a new build of
restlet and trying to post json data back to a resource.
 It will accept and process xml just fine but trying to post
application/json always gets back a http 415 return code.  These are the
libraries we have in the sample code:

org.restlet.ext.jaxb.jar   org.restlet.ext.xml.jar
org.json_2.0
org.restlet.ext.jaxrs.jar
org.restlet.jar

Also attached is jax-rs resource file and the json that we are trying to
POST.

Tried using the xstream library but the json produced is very different from
the normal json and will not work with our browser code.

Any thoughts are greatly appreciated.

 Thanks
    Chris

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=7458&dsMessageId=24123
33

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=7458&dsMessageId=2413797
Christopher B. Olsen

RE: JAX-RS and JSon

Reply Threaded More More options
Print post
Permalink
Jerome,
 Before I posted the last message I had tried running things with xstream as well.  The JSON output produced by jettison I believe is using the default BadgerFish mapping which is very verbose.  I tried to feed that output back using a POST and was getting the 415 returns as well.  Want to change the JSON output to the "mapped" output but so far have not got that working.

 Using the xstream modules what does the code expect so that it can map back to the POJO?
And do you know of any sample code where this is working with JAX-RS ?

  Thanks again
    Chris Olsen

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=7458&dsMessageId=2416841
webpost

RE: JAX-RS and JSon

Reply Threaded More More options
Print post
Permalink
Was able to get things to work with a svn build of the software.  JSON data sent to JAX-RS and it un-marshaled just fine.
Looking at the source does look like you are using the mapped jettison model, but boy is it verbose.  The producing JSON which is supposed to be compact quick way to send data to the browser is twice as big as the original JSON produced and half again as big as the xml.
Looks like there is a way to alias the full class name's in xstream, would you guys entertain doing something like that. Or if we could figure out a way to get the class names out of the JSON full stop.

  Thanks!
    Chris Olsen

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=7458&dsMessageId=2417805