users@jersey.java.net

Re: [Jersey] passing in JSON to create a resource

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 30 Jul 2009 07:34:34 +0200

Hi,

The current documentation is here:

https://jersey.dev.java.net/documentation/1.1.1-ea/user-guide.html#json

Unfortunately there is currently no document formally describing the
mapping of the JAXB conventions (mapping from XSD say).

So currently you need to work from looking at the serializations
produced by Jersey from the GET request. Often showing examples of
JSON is a common way to document the representation. As i understand
there is progression towards a JSON-based schema, so if this becomes
popular i might expect that would be a better way to document (with
examples).

Paul.


On Jul 29, 2009, at 6:09 PM, Jesus M. Rodriguez wrote:

> Are there any docs on being able to POST JSON and having it create
> an object?
>
> For example,
>
> @POST
> @Consumes("application/json")
> public void doSomething(MyDomainObject do) {
> log.debug("we have a domain object');
> }
>
> The client (python in my case) would
>
> params = urllib.urlencode({"name":"somevalue","uuid":"someuuid"})
> headers = {"Content-type":"application/json",
> "Accept": "application/json"}
> conn = httplib.HTTPConnection("localhost", 8080)
> conn.request("POST", '/myurl/, params, headers)
> response = conn.getresponse()
> print("Status: %d Response: %s" % (response.status, response.reason))
> rsp = response.read()
> conn.close()
>
> What I want to happen is the above JSON gets transformed into a
> MyDomainObject.
> MyDomainObject is annotated right enough to have it serialized as JSON
> in a GET method
> but how do I do it the other way?
>
> Sincerely,
> jesus
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>