我試圖做一個RESTful Web服務是採用XML請求,併產生XML響應,我使用彈簧4.3.5它...彈簧4 RestController不映射XML請求正確
的問題是,當我使用postman發佈了一個post請求,並且在我的服務方法中添加了一個調試,這比我發現xml請求屬性沒有使用播放器POJO進行映射/反序列化。
任何幫助將是appreciated..Thanks
@RestController
public class SyncRestfulService {
LoggerManager loggerManager = new LoggerManager();
@RequestMapping(value = RestURIConstants.SAMPLE_POST_PLAYER, method = RequestMethod.POST, headers = {
"Content-type=application/xml" })
public Player getPlayer(Player requestEntity) {
loggerManager.info(LoggerConstantEnum.SyncRestfulService ,
"| <AbilitySyncRestfulService> Method: getPlayer " + requestEntity);
loggerManager.info(LoggerConstantEnum.SyncRestfulService , "Id : ", requestEntity.getId());
return requestEntity;
}
}
請求XML數據
//Request
<player>
<id>1</id>
<matches>251</matches>
<name>Anand</name>
</player>
//response xml data
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<player>
<id>0</id>
</player>
// JAXB POJO
@XmlRootElement(name = "player")
@XmlAccessorType(XmlAccessType.NONE)
public class Player {
private int id;
private String name;
private String matches;
public int getId() {
return id;
}
@XmlElement(name = "id")
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
@XmlElement(name = "name")
public void setName(String name) {
this.name = name;
}
public String getMatches() {
return matches;
}
@XmlElement(name = "matches")
public void setMatches(String matches) {
this.matches = matches;
}
}
附加產生= { \t \t \t MediaType.APPLICATION_XML_VALUE}在你的控制器 –
,做u有配置豆到XML轉換成POJO,反之亦然應用-context.xml文件 –
正確的,如果我錯了,我想在春天4我們不需要添加轉換器。和它的正確生產XML我已經測試過,但在案件問題是映射後身體XML字符串到「Playter playter」 –