env: spring boot 2.0,jackson serialization
my rest controller method will not return any body,just like ResponseEntity.ok().build(),but the ajax don't go to success method,it will go to error emthod,and the error shows "Unexpected end of JSON input"
i tried this:
1. add the properties into application.properties : spring.jackson.default-property-inclusion: NON_NULL, it still go to error method;
2. update return result like this ResponseEntity.ok("{}"),it will ok;
@PostMapping(value = "/import")
public ResponseEntity<Void> importRecipients(@ModelAttribute UserRecipientDto userRecipientDto,
@CurrentUser @ApiIgnore User user,
@RequestParam ImportType importType,
@RequestParam String name,
@RequestParam List<Long> ids) {
Collection<MailRecipient> count = this.service.getRecipients(userRecipientDto, importType, ids);
UserMailRecipientGroup userMailRecipientGroup = new UserMailRecipientGroup(name, USER_RECIPIENT, count, user);
userMailRecipientGroupService.saveMailRecipientGroup(userMailRecipientGroup);
return ResponseEntity.ok().build();
}
application.yml:
spring:
jackson:
serialization:
write-dates-as-timestamps: true
write_dates_with_zone_id: true
time-zone: GMT
default-property-inclusion: NON_NULL
ajax code block:
url: url,
type: type,
contentType: "application/json;charset=utf-8",
headers: {},
data: param,
async: true,
dataType: "json",
success: function success(data) {
cb(data);
},
error: function error(request, status_code, text_error) {}
i expect this:
when my rest method return ok().build(), the ajax will go to success method.
i guess ajax convert result to json occur some error, may be some spring boot properties will do it, but i haven't found yet.
thanks!!
Not clear what class your controller is extending and the import of your ok() method.
Maybe try with ResponseEntity