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:

1 comment:

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