When the consumer makes a Rest Call to Provider, Provider Should return the response depends on consumer Request.How to construct REST API to Support both XML and JSON.
Discussion posts and replies are publicly visible
kiranj0001 , hope the below link will help you to build rest API which supports the different format, whenever the user is calling the rest API, a user needs to specify in which format he is expecting the response www.vogella.com/.../article.html
You may want to do something like this below:
/* Assuming the consumer request passes a parameter contentFormat with values either JSON or XML
* Get the requestFormat
*/
local!requestFormat: nvl(http!request.queryParameters.contentFormat."JSON")
/* Set contentType to set in response based on request Format
local!contentType: if( local!requestFormat="JSON", "application/json", "application/xml")
/
*
* Do some application logic and set local!data as data to be sent back as response.
a!httpResponse(
/*
* set content-type based on local!contentType
headers: {
a!httpHeader(name: "Content-Type", value: local!contentType)
},
* use tojson or toxml based on requestFormat
body: if( local!requestFormat="JSON", a!toJson(local!data), toxml(local!data))
a!toJson(local!data),
)
you should use spring boot to develop rest api and add dependency
<dependency> <groupId>com.fasterxml.jackson.dataformat</groupId> <artifactId>jackson-dataformat-xml</artifactId> </dependency>
Now spring boot will support for both format xml and json .
www.javavogue.com/.../