My application has an REST interface and I must customize the rendering of the result body in case that a controller returns ResponseEntity<>(NOT_FOUND)
as the controller with the following method it does:
@Override
public ResponseEntity<ScimCoreUser> getUserById(String userid) {
Optional<ScimCoreUser> result = service.findUserByNumber(userid);
return result.map(user -> new ResponseEntity<>(user, HttpStatus.OK))
.orElseGet(() -> new ResponseEntity<>(HttpStatus.NOT_FOUND));
}
I cannot change the signature of the method, as I must impement a generated interface. I know what I could simple throw a custom exception and handle this exception with a controller advice.
Does someone know how to take over the rendering of the result body for ResponseEntity<>(HttpStatus.NOT_FOUND))
, so that I can return an error message in the following format as defined in RFC 7644: System for Cross-domain Identity Management: Protocol:
{
"schemas": ["urn:ietf:params:scim:api:messages:2.0:Error"],
"detail":"Resource 2819c223-7f76-453a-919d-413861904646 not found",
"status": "404"
}