私はスプリング ブート レスト アプリケーションに取り組んでおり、xml 応答を送り返す必要があるシナリオがあります。以下のように JAXB クラスを作成しました。
@XmlRootElement(name = "Response")
public class ResponseDTO{
private String success;
private List<String> xmls;
}
私のコントローラークラスは以下の通りです:
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);
}
}
そして、私は以下のようなxml応答を期待しています:
<Response>
<success>true</success>
<xmls>
<triggerProcess id = '1'>
<code>true</code>
</triggerProcess>
<triggerProcess id = '2'>
<code>false</code>
</triggerProcess>
</xmls>
</Response>
つまり、文字列値 (xml1 と xml2 も xml に変換する必要があります)。しかし、私は以下のようになっています:
<Response>
<success>true</success>
<xmls>
<triggerProcess id = '1'><code>true</code></triggerProcess><triggerProcess id = '2'><code>false</code></triggerProcess>
</xmls>
</Response>
ここで、xml (xml1 および xml2) は xml に変換されず、要素の文字列値として表示されます。例外として出力を取得するのを手伝ってくれる人はいますか。前もって感謝します。