0
我正在使用RESTEasy編寫一個RESTful Web服務並試圖編寫包含HashMap的響應。 Web服務生成JSON或XML。 JSON映射是正確的,但XML映射沒有內容。 RESTEasy @WrappedMap註解應該將地圖編組爲XML。RESTEasy @ WrappedMap
@XmlRootElement(name="Response")
public class RootResponse {
private HashMap<String, String> test;
public RootResponse() {
test = new HashMap<String, String>();
test.put("Fred", "Wilma");
test.put("Barney", "Betty");
}
@XmlElement
@WrappedMap(map="test", key="name", entry="spouse")
public HashMap<String, String> getTest() {
return this.test;
}
}
JSON輸出:
{
"test": {
"Fred": "Wilma",
"Barney": "Betty"
}
}
XML輸出:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Response>
<test/>
</Response>
我得到的結果相同,如果我離開了@WrappedMap註解。
@WrappedMap不適用於屬性嗎?