I am writing a simple spring boot REST API for fun. Spring boot is new for me. By call the "/search" i get following exception:
Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: No converter found for return value of type: class java.util.LinkedHashMap
My Code:
@PostMapping("/search") public ResponseEntity getSearchResultViaAjax(@Valid @RequestBody SearchCriteria search, Errors errors) {
ResponseBody result = new ResponseBody();
//If error, just return a 400 bad request, along with the error message
if (errors.hasErrors()) {
result.setMsg(errors.getAllErrors().stream().map(x -> x.getDefaultMessage()).collect(Collectors.joining(",")));
return ResponseEntity.badRequest().body(result);
}
List<User> users = userService.findByUserNameOrEmail(search.getUsername());
if (users.isEmpty()) {
result.setMsg("no user found!");
} else {
result.setMsg("success");
}
result.setResult(users);
return ResponseEntity.ok(result);
}
Any help would be greatly appreciated.
Thanks in advance!