• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Using different Content Types for REST Webservices

 
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic