The problem is binding javascript arraylist with RequestParam annotation.
I have a form data like this works fine if there is no nokDataList.
nokInfoDatas is an javascript array that in console it looks:
var requestData = JSON.stringify(nokInfoDatas);
console.log("nokInfoDatas");
console.log(nokInfoDatas);
console.log("requestData");
console.log(requestData);
var fd = new FormData();
fd.append('photo', file);
fd.append('testId', testId);
fd.append('nokDataList', nokInfoDatas);
var ajaxData = {
type: "POST",
data: fd,
processData : false,
contentType : false,
url: sendUrl,
headers: headersData,
};
Backend side:
public @ResponseBody String answer(HttpServletRequest request,
@RequestParam(value = "photo") MultipartFile photo,
@RequestParam(value = "testId") String testId,
@RequestParam(value = "nokDataList") List<NokDataDTO> nokInfoDtos
)
You can try as follows :
Create a Blob with your JSON data (requestData) :
var requestData = JSON.stringify(nokInfoDatas);
var fd = new FormData();
fd.append('photo', file);
fd.append('testId', testId);
fd.append('nokDataList', new Blob([requestData], {
type: "application/json"
}));
Change @RequestParam to @RequestPart for parsing JSON with multi-part.
public @ResponseBody String answer(HttpServletRequest request,
@RequestParam(value = "photo") MultipartFile photo,
@RequestParam(value = "testId") String testId,
@RequestPart(value = "nokDataList") List<NokDataDTO> nokInfoDtos
)