Jesus,
Take a look at using Jersey with JAXB. It allows you to easily handle json and xml being turned into your domain object and vice versa.
________________________________
From: Jesus M. Rodriguez <jmrodri_at_gmail.com>
To: users_at_jersey.dev.java.net
Sent: Wednesday, July 29, 2009 9:09:20 AM
Subject: [Jersey] passing in JSON to create a resource
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