问题是,如何将json对象中的数组自动读取到权限集?
我试图将rest body中接收到的json对象转换为USER类的对象:
public class User {
public String userid;
public String password;
private String fullname;
private String email;
private String websettings;
private String productionlines;
private String language;
private String statustracking;
private String createdate;
public Set<Authority> authorities;
}
Authority.java版本:
public final class Authority implements Serializable {
private String authority;
private String userid;
public Authority(String authority, String userid) {
this.authority = authority;
this.userid = userid;
}}
这是我得到的json对象:
{
"userid":"xx.xx",
"password":"",
"fullname":"asdfasdf",
"email":"ali@sdf.com",
"websettings":"this is setting",
"productionlines":"production lines.",
"createdate":"1234345",
"statustracking":"status tracking...",
"authorities" : [
"user", "admin"
]
}
我就是这么吃的:
public User createUser(@Valid @RequestBody User user) {
return userService.createUser(user.getUserid(), user.password, user.getFullname(), user.getEmail(), null, getUserAuthorities(user));
}