Search code examples
jsonspringrestful-architecture

Suggestion required: RESTFUl webservice transform xml to Json


Hi I am new to Java and not sure how to proceed (kindly ignore any typos or my language). Can somebody help me out (just the Idea/how to proceed, dont need any sample code). I am trying to create a Restful Json webservice (using Spring MVC). The webservice that I am trying to create is kind of a wrapper for an existing XML based restful webservice. The Idea is to have one common platform, since all other existing services are exposed as as JSON services. My job is to fetch the XML transform it into a Json, but the tricky part is The Json schema is a superset of the XML schema (I mean it contains more elements that get filled with some default values). Please let me know if you need more info.

Thanks in advance.


Solution

  • One way to do it would be to use Jaxb to transform the the incoming XML to Java Objects. Build your Jaxb objects in a way that it contains all the elements, the one with default values and the elements in the incoming XML.

    Ones the XMl is converted into Jaxb you can use org.springframework.http.converter.json.MappingJacksonHttpMessageConverter message converter to convert your Jaxb object to Json string.