【发布时间】:2017-12-13 10:36:49
【问题描述】:
我使用具有方法的外部库:
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");
}
}
我有一个返回该对象实例的@RequestMapping:
@RequestMapping(value = "/authorities", method = GET)
public ResponseEntity getAuthorities() {
return new ResponseEntity<>(authenticatedUser.getAuthentication(), HttpStatus.OK); //getAuthentication returns CustomUserDetails instance
}
我得到了
org.springframework.http.converter.HttpMessageNotWritableException: Could not write content: Not allowed.
我该如何处理? Ingore 或为此属性设置一些默认值。
UPD我无法将 @JsonIngore 添加到该类,因为它不是我的库,我无权访问它的源代码。
【问题讨论】:
-
@EbrahimPoursadeqi 这个帖子如何解决我的问题??
-
使用 Jackson mixins 来克服 3rd 方的限制。
-
我添加了一个重复的链接。
-
@SotiriosDelimanolis 谢谢。我已经成功了)
标签: java json spring-mvc jackson