我的@RestController中的方法正在接收以下JSON字符串,但未绑定到我的类:json = {
"rsnumberRows": {
"lnumberRows": 23,
"tprocessCode": "w",
"lanomIdx": 123
},
"rsdoorInfo": {
"lnumOfDoors": 5,
"tdoorNum": {
"0": "701",
"1": "702",
"2": "703",
"3": "704",
"4": "705"
},
"tdoorUnavailStartDate": {
"0": "18-JUN-2015 15:51:00",
"1": "19-JUN-2015 15:51:00",
"2": "18-JUN-2015 15:51:00",
"3": "13-JUN-2015 15:51:00",
"4": "18-JUN-2015 15:51:00"
},
"wtrailerMoveRequiredInd": {
"0": 1,
"1": 1,
"2": 0,
"3": 1,
"4": 0
},
"tdoorUnavailEndDate": {
"0": "17-JUN-2015 15:51:00",
"1": "17-JUN-2015 15:51:00",
"2": "17-JUN-2015 15:51:00",
"3": "17-JUN-2015 15:51:00",
"4": "17-JUN-2015 15:51:00"
}
}
}
控制器:@RequestMapping(path="/SchdDoorMaintenance", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public SchdUpdDoorInfResponse updateDoor(@RequestBody SchdUpdDoorInfJS rSchdUpdDoorInf)
{
return schdDoorMaintenanceService.schdUpdDoorInf(rSchdUpdDoorInf);
}
接收Json数据的类是:
public class SchdUpdDoorInfJS {
public SCHDSNumberRowsJS rsNumberRows;
public SCHDSDoorInfoJS rsDoorInfo;
public SCHDSNumberRowsJS getRsNumberRows() {
return rsNumberRows;
}
public void setRsNumberRows(SCHDSNumberRowsJS rsNumberRows) {
this.rsNumberRows = rsNumberRows;
}
public SCHDSDoorInfoJS getRsDoorInfo() {
return rsDoorInfo;
}
public void setRsDoorInfo(SCHDSDoorInfoJS rsDoorInfo) {
this.rsDoorInfo = rsDoorInfo;
}
}
public class SCHDSDoorInfoJS implements Serializable{
public int lNumOfDoors;
public List<String> tDoorNum;
public List<String> tDoorUnavailStartDate;
public List<String> tDoorUnavailEndDate;
public List<Integer> wTrailerMoveRequiredInd;
public int getlNumOfDoors() {
return lNumOfDoors;
}
public void setlNumOfDoors(int lNumOfDoors) {
this.lNumOfDoors = lNumOfDoors;
}
public List<String> gettDoorNum() {
return tDoorNum;
}
public void settDoorNum(List<String> tDoorNum) {
this.tDoorNum = tDoorNum;
}
public List<String> gettDoorUnavailStartDate() {
return tDoorUnavailStartDate;
}
public void settDoorUnavailStartDate(List<String> tDoorUnavailStartDate) {
this.tDoorUnavailStartDate = tDoorUnavailStartDate;
}
public List<String> gettDoorUnavailEndDate() {
return tDoorUnavailEndDate;
}
public void settDoorUnavailEndDate(List<String> tDoorUnavailEndDate) {
this.tDoorUnavailEndDate = tDoorUnavailEndDate;
}
public List<Integer> getwTrailerMoveRequiredInd() {
return wTrailerMoveRequiredInd;
}
public void setwTrailerMoveRequiredInd(List<Integer> wTrailerMoveRequiredInd) {
this.wTrailerMoveRequiredInd = wTrailerMoveRequiredInd;
}
} 和
public class SCHDSNumberRowsJS implements Serializable{
public Integer lNumberRows;
public Integer lAnomIdx;
public String tProcessCode;
public Integer getlNumberRows() {
return lNumberRows;
}
public void setlNumberRows(Integer lNumberRows) {
this.lNumberRows = lNumberRows;
}
public Integer getlAnomIdx() {
return lAnomIdx;
}
public void setlAnomIdx(Integer lAnomIdx) {
this.lAnomIdx = lAnomIdx;
}
public String gettProcessCode() {
return tProcessCode;
}
public void settProcessCode(String tProcessCode) {
this.tProcessCode = tProcessCode;
}
} 我确实在请求体中收到了Json字符串,但由于某种原因,这些值没有绑定到类。任何帮助将不胜感激。谢谢。
答案 0 :(得分:0)
某些属性被定义为json中的对象以及java tdoorNum
,tdoorUnavailStartDate
,wtrailerMoveRequiredInd
和tdoorUnavailEndDate
中的列表。
在json中使用[
和]
定义您的列表,如下所示:
"tdoorNum": [
"701",
"702",
"703",
"704",
"705"
]