- 我有以下JSON:
{
"return": [
{
"admin": false,
"alias": "",
"email": "",
"emailId": {"value": 0},
"groups": [],
"id": {"value": 1},
"locked": false,
"loggedInCount": 0,
"master": true,
"sms": "",
"smsId": {"value": 0},
"type": "POWER",
"username": "NGCP"
},
{
"admin": false,
"alias": "",
"email": "",
"emailId": {"value": 0},
"groups": [{"value": 2}],
"id": {"value": 3},
"locked": false,
"loggedInCount": 0,
"master": false,
"sms": "",
"smsId": {"value": 0},
"type": "POWER",
"username": "POLICY"
}
]
}
用户模型类的保存:
@JsonIgnoreProperties(ignoreUnknown = true)
public class User {
public User(){
}
private boolean admin;
private String alias;
private String email;
private String emailId;
private ArrayList<String> groups;
private String id;
private boolean locked;
private int loggedInCount;
private boolean master;
private String sms;
private String smsId;
private String type;
private String userName;
//getter and setters
}
现在我正在使用“RestTemplate”来获取结果。
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<User[]> response = restTemplate.exchange(URL_GET,HttpMethod.GET,request, User[].class);
我遇到了一个错误。我知道这是因为主键是“result”,但我能否指定从哪里应该restTemplate解析JSON?
是否可以在类似于“emailId”的字段上指示直接获取值?有些模板可以做到吗?