Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using different Content Types for REST Webservices

 
Rahul Babbar
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic