I have this method in controller
@RequestMapping(value = "/updateWithParams", method = RequestMethod.GET)
@ResponseBody
public List<ResolutionDto> updateWithParams() {
List<ResolutionDto> list = new ArrayList<>();
List<Resolution> resolutions = resolutionService.findAll();
for (Resolution resolution : resolutions) {
list.add(new ResolutionDto(resolution.getId(), resolution.getName(), resolution.getStatus(), resolution.getDateCreated(), resolution.getUserName()));
}
return list;
}
It is ResolutionDto
@Data
@AllArgsConstructor
public class ResolutionDto {
public Long id;
private String name;
private Integer status;
private Date dateCreated;
private String userName;
}
And on Client side I want get this array like JSON array and fill jQuery DataTable.
function loadTable() {
$.ajax({
type: 'GET',
dataType: "json",
url: '/updateWithParams',
success: function (data) {
var jsdata = JSON.parse(data);
var datatable = $('#example').dataTable().api();
datatable.fnAddData(jsdata);
},
error: function (xhr, str) {
alert("error");
}
});
}
But it not work. I thik problem in this line var jsdata = JSON.parse(data);
but I do not understand how fix it