-1

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.

Ravi
  • 13
  • 2

1 Answers1

1

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.

EyalBellisha
  • 1,874
  • 19
  • 28
Johnson Abraham
  • 771
  • 4
  • 12
  • Hi Grantham, thanks for a quick reply :). The trouble I am facing is that the naming convention of the elements in XML and Json differ. I was thinking of creating two sets of POJO's one based on XML and other based on Json and manually fill the Json POJO and finally get the Json using Jackson. Is there a way to avoid two sets of POJOs since they have different naming conventions? Thanks for the help. – Ravi May 01 '13 at 14:59
  • You can use **@JsonProperty** annotation. That way you can use only one set of POJO's and still achieve what you want. – Johnson Abraham May 01 '13 at 19:38