I use an external library that has a method:
public class CustomUserDetails implements UserDetails {
private final User principal;
private final Collection<GrantedAuthority> authorities;
//constructor, getters, setters
@Override
public String getPassword() {
throw new UnsupportedOperationException("Not allowed");
}
}
And I have a @RequestMapping that returns an instance of that object:
@RequestMapping(value = "/authorities", method = GET)
public ResponseEntity getAuthorities() {
return new ResponseEntity<>(authenticatedUser.getAuthentication(), HttpStatus.OK); //getAuthentication returns CustomUserDetails instance
}
And I'm getting
org.springframework.http.converter.HttpMessageNotWritableException: Could not write content: Not allowed
.
How can I handle this? Ingore or set some default value to this property.
UPD I cannot add @JsonIngore to that class because it's not my library, I don't have access to its source.