Monday, 21 June 2010

Java: Using Jersey with JAXB to output XML or JSON.

A very brief (and simple) example of the principle behind harnessing Jersey's content negotiation ability whilst taking advantage of JAXB to marshall a bean from a Java Object to XML/JSON:



And the resource:


Testing the resource(s) using curl:

Which would yield:

or:

Which would yield:

2 comments:

Vijayan Srinivasan said...

Thanks for the Sample, especially your curl example to call the service in JSON mode.

I completed an service that produces both XML and JSON, When invoking it was always giving XML as I was missing Accept: application/json

for IT the said...

Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training in India . Nowadays Java has tons of job opportunities on various vertical industry.


or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry.