users@jersey.java.net

passing in JSON to create a resource

From: Jesus M. Rodriguez <jmrodri_at_gmail.com>
Date: Wed, 29 Jul 2009 12:09:20 -0400

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