ジャクソン パーサー、ajax、および jquery を介してオブジェクトの配列をコントローラーに渡す際に問題が発生しています。
私のコントローラーは次のようになります。
@RequestMapping(value="/saveTimeBooking")
public @ResponseBody ReturnTO saveTimeBooking(@RequestBody TimesheetTO timesheetTO[]) {
// ...
}
私の Java オブジェクト TimesheetTO は次のようになります。
public class TimesheetTO implements Serializable {
private static final long serialVersionUID = 1L;
private int activityMasterId;
private String name;
private BigDecimal mondayEffort=new BigDecimal(0);
private BigDecimal tuesdayEffort=new BigDecimal(0);
private BigDecimal wednesdayEffort=new BigDecimal(0);
private BigDecimal thursdayEffort=new BigDecimal(0);
private BigDecimal fridayEffort=new BigDecimal(0);
private BigDecimal saturdayEffort=new BigDecimal(0);
private BigDecimal sundayEffort=new BigDecimal(0);
public int getActivityMasterId() {
return activityMasterId;
}
public String getName() {
return name;
}
public BigDecimal getMondayEffort() {
return mondayEffort;
}
public BigDecimal getTuesdayEffort() {
return tuesdayEffort;
}
public BigDecimal getWednesdayEffort() {
return wednesdayEffort;
}
public BigDecimal getThursdayEffort() {
return thursdayEffort;
}
public BigDecimal getFridayEffort() {
return fridayEffort;
}
public BigDecimal getSaturdayEffort() {
return saturdayEffort;
}
public BigDecimal getSundayEffort() {
return sundayEffort;
}
public void setActivityMasterId(int activityMasterId) {
this.activityMasterId = activityMasterId;
}
public void setName(String name) {
this.name = name;
}
public void setMondayEffort(BigDecimal mondayEffort) {
this.mondayEffort = mondayEffort;
}
public void setTuesdayEffort(BigDecimal tuesdayEffort) {
this.tuesdayEffort = tuesdayEffort;
}
public void setWednesdayEffort(BigDecimal wednesdayEffort) {
this.wednesdayEffort = wednesdayEffort;
}
public void setThursdayEffort(BigDecimal thursdayEffort) {
this.thursdayEffort = thursdayEffort;
}
public void setFridayEffort(BigDecimal fridayEffort) {
this.fridayEffort = fridayEffort;
}
public void setSaturdayEffort(BigDecimal saturdayEffort) {
this.saturdayEffort = saturdayEffort;
}
public void setSundayEffort(BigDecimal sundayEffort) {
this.sundayEffort = sundayEffort;
}
public TimesheetTO(){}
public TimesheetTO( String activityMasterId,
String name,
String mondayEffort,
String tuesdayEffort,
String wednesdayEffort,
String thursdayEffort,
String fridayEffort,
String saturdayEffort,
String sundayEffort)
{
this.activityMasterId=Integer.parseInt(activityMasterId);
this.name=name;
this.mondayEffort=BigDecimal.valueOf(Double.parseDouble(mondayEffort));
this.tuesdayEffort=BigDecimal.valueOf(Double.parseDouble(tuesdayEffort));
this.wednesdayEffort=BigDecimal.valueOf(Double.parseDouble(wednesdayEffort));
this.thursdayEffort=BigDecimal.valueOf(Double.parseDouble(thursdayEffort));
this.fridayEffort=BigDecimal.valueOf(Double.parseDouble(fridayEffort));
this.saturdayEffort=BigDecimal.valueOf(Double.parseDouble(saturdayEffort));
this.sundayEffort=BigDecimal.valueOf(Double.parseDouble(sundayEffort));
}
}
また、次の jquery コードを使用して、タイムシート オブジェクトの配列をコントローラーに渡しています。
var datacounter=0;
/*var totalcount=0;*/
var timesheetTO = new Array();
$("#timeSheetTableId input[id^=activityMasterId]").each(function() {
$('#activityMasterId_'+datacounter).removeAttr('disabled');
$('#name_'+datacounter).removeAttr('disabled');
timesheetTO.push({
"activityMasterId": $('#activityMasterId_'+datacounter).val(),
"name": $('#name_'+datacounter).val(),
"mondayEffort": new Integer($('#mondayEffort_'+datacounter).val()),
"tuesdayEffort": $('#tuesdayEffort_'+datacounter).val(),
"wednesdayEffort": $('#wednesdayEffort_'+datacounter).val(),
"thursdayEffort": $('#thursdayEffort_'+datacounter).val(),
"fridayEffort": $('#fridayEffort_'+datacounter).val(),
"saturdayEffort": $('#saturdayEffort_'+datacounter).val(),
"sundayEffort": $('#sundayEffort_'+datacounter).val()
});
datacounter=datacounter+1;
});
var url = contextRoot + "timesheet/saveTimeBooking.htm";
$.ajax({
type : 'POST',
url : url,
async : false,
timeout : 5000,
contentType: 'application/json',
dataType: 'json',
data : {
timesheetTO : JSON.stringify(timesheetTO)
},
success : function(data, textStatus) {
alert('successful');
},
error : function(xhr, textStatus, errorThrown) {
alert('request failed in saving timesheet:' + errorThrown + " " + textStatus + " "
+ xhr.toString());
}
});
送信中に、上記のエラーが表示されます: Jacskon パーサー例外: 認識されないトークン 'tieheT': 'null'、'true' または 'false' が必要でした
私は何を間違っていますか..これを修正する方法はありますか?
の結果は次のJSON.stringify
とおりです。
[{"activityMasterId":"1","name":"Financial Implications","mondayEffort":"0","tuesdayEffort":"0","wednesdayEffort":"0","thursdayEffort":"0","fridayEffort":"0","saturdayEffort":"0","sundayEffort":"0"},{"activityMasterId":"2","name":"Cost estimation","mondayEffort":"0","tuesdayEffort":"0","wednesdayEffort":"0","thursdayEffort":"0","fridayEffort":"0","saturdayEffort":"0","sundayEffort":"0"}]