I need to include some JSON data inside an XML output (I know it might not be the best way, but the system requires it). This problem is part of a Spring REST project. The Java method which generates the XML is annotated as
@RequestMapping(value = "/TEST/pid",
method = RequestMethod.GET, produces = "application/xml")
public String xmlGenerator(String pid){
// definition
}
I could incorporate the JSON data inside the XML output, but the JSON data is not pretty printed. The JSON data is pretty printed before it gets inserted into the XML, but within the XML the JSON is prints out everything in a line. The XML output with JSON data is as follows. Any suggestion how I could pretty print the JSON; the XML is already pretty printed. Appreciate any help. Thanks!
<asec ID="1234-AM0">
<wrap MIMETYPE="application/json" LABEL="JSON DATA">
<xmlData>
<asTest>
{ "pid" : "112233", "pData" : { "type" : "image", "derivatives" : [ { "url" : "//test/url/test1.jpg", "width" : "1538", "height" : "600", "size" : "45168" }, { "url" : "//test/url/test2.jpg", "width" : "64", "height" : "64", "size" : "890" }, { "url" : "//test/url/test3.jpg", "width" : "2888", "height" : "1127", "size" : "180680" } ] } }
</asTest>
</xmlData>
</wrap>
</asec>
--EDIT--
Not sure why someone would mark the question as duplicate. My question is not how to pretty print JSON in Java, I could do that already. My question is how to pretty print the JSON content inside an XML output.