-
Notifications
You must be signed in to change notification settings - Fork 541
Closed
Labels
Milestone
Description
使用Spring Security时,实体类实现UserDetails时使用@JSONField(serialize = false)不序列化authorities无效
public static void main(String[] args) {
TestUser testUser = new TestUser();
testUser.setUsername("test");
testUser.setPassword("123456");
testUser.setAuthorities(Sets.newHashSet());
String s = JSON.toJSONString(testUser);
System.out.println(s);
}
@Data
public static class TestUser implements UserDetails {
private String username;
private String password;
@JSONField(serialize = false)
private Set<GrantedAuthority> authorities;
@Override
@JSONField(serialize = false)
public boolean isAccountNonExpired() {
return true;
}
@Override
@JSONField(serialize = false)
public boolean isAccountNonLocked() {
return true;
}
@Override
@JSONField(serialize = false)
public boolean isCredentialsNonExpired() {
return true;
}
@Override
@JSONField(serialize = false)
public boolean isEnabled() {
return true;
}
}
输出结果为{"authorities":[],"password":"123456","username":"test"}
期望为{"password":"123456","username":"test"}