File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services and the fly likes Using different Content Types for REST Webservices Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Using different Content Types for REST Webservices" Watch "Using different Content Types for REST Webservices" New topic
Author

Using different Content Types for REST Webservices

Rahul Babbar
Ranch Hand

Joined: Jun 28, 2008
Posts: 210
Hi all,

We have implemented a REST webservice layer to access the application.

The webservice layer handles XML as the content type from the POST request and as a return for GET request.

However, the new requirement states that it should be able to consume and respond with JSON also along with XML.

One solution that i can think of is to have a Servlet Filter for the requests to the Webservice which will convert JSON to XML or XML to JSON depending on the content type of the request.

Is there any other way to this.

Thank you

Rahul


Rahul Babbar
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Having a servlet filter convert XML to JSON or vice versa is rather inefficient.
I recommend using JAX-RS and the @Produces annotation.
You can either annotate one single web service method with @Produces({"application/xml","application/json"}) or annotate two different web service methods with @Produces("application/xml") and @Produces("application/json").
Best wishes!

My free books and tutorials: http://www.slideshare.net/krizsan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using different Content Types for REST Webservices