Habchi Habchi - 9 months ago 69
JSON Question

Rest facade to map xml to json

I'm confronted to a problem between two applications that we are using in my company. A CRM called Infonova and a mobile application.

The two applications have their own API, one is giving responses in xml format and the other one in Json.

The solution that I'm thinking to implement is to create an application that will be a facade API (gateway). This application will call the url API of the first application and will get xml response, and I'm thinking to map this solution to a json format and return it.

Since the attributes between xml and json are not the same, I want to know if there's a solution to map the two entities that will represent my responses.

Thanks in advance,

Answer Source

You could define an XML unmarshaller with spring, call your service that returns xml, unmarshal response to that bean. And then you could return this bean in response from a controller annotated with @Produces("application/json").

So, to sum it up. You have a controller that produces json, a bean containing field names you want in your json, and a custom unmarshaller for xml to populate those fields (custom because the field names between json and xml do not match).