2 回答
TA贡献2080条经验 获得超4个赞
使用 @JsonProperty 将输出字符串映射到您的 DTO ex:
@JsonProperty("authorizationToken") 私有字符串 authToken;
并继续在 ResponseEntity 中使用对象而不是 String
ResponseEntity<SecurityToken> responseEntity = new RestTemplate().postForEntity( endpoint, credentials, SecurityToken.class );
TA贡献1874条经验 获得超12个赞
它适用于方法的这种实现getPolicyHolders():
@GetMapping("/policyholders")
public PolicyHolderBean getPolicyHolders() {
HttpEntity<String> request =
new HttpEntity<String>(setHeaders());
ResponseEntity<String> responseEntity = new RestTemplate().exchange(
"https://api.sandbox.socotra.com/policyholders",
HttpMethod.GET,
request,
String.class
);
String output = responseEntity.getBody();
Gson gson=new Gson();
PolicyHolderBean policyHolders=gson.fromJson(output,PolicyHolderBean.class);
return policyHolders;
}
添加回答
举报