I am working on spring-boot rest application and I have a scenario where I need to send back a xml response. For which I have created a JAXB class as below:
@XmlRootElement(name = "Response")
public class ResponseDTO{
private String success;
private List<String> xmls;
}
and my controller class is as below:
public class MyController{
@RequestMapping(value = "/processrequest/v1", method = RequestMethod.POST, produces = "application/xml")
public ResponseEntity processHotelSegments(@RequestBody String xmlString) {
ResponseDTO response = new ResponseDTO();
response.setSuccess("true");
String xml1 = "<triggerProcess id = '1'><code>true</code> </triggerProcess>";
String xml2 = "<triggerProcess id = '2'><code>false</code></triggerProcess>";
List<String> list = new ArrayList<>();
list.add(xml1);
list.add(xml2);
response.setXmls(list);
return new ResponseEntity<>(response, HttpStatus.CREATED);
}
}
And I am expecting the xml response as below:
<Response>
<success>true</success>
<xmls>
<triggerProcess id = '1'>
<code>true</code>
</triggerProcess>
<triggerProcess id = '2'>
<code>false</code>
</triggerProcess>
</xmls>
</Response>
i.e, the String values(xml1, and xml2 should be converted to xml as well). But I am getting the as below:
<Response>
<success>true</success>
<xmls>
<triggerProcess id = '1'><code>true</code></triggerProcess><triggerProcess id = '2'><code>false</code></triggerProcess>
</xmls>
</Response>
where in the xmls (xml1 and xml2) are not converted to xml, instead they are displayed as the String value of elements. Can anybody help me out in obtaining the output as excepted. Thanks in advance.