我有一个 Restcontroller 类 -PolicyHoldersController- 向返回 JSON 对象的 API 发出 GET 请求。当我点击 RestController URL 时,我得到 null,虽然响应状态是 200。我相信我得到了一个有效负载,但我没有正确地将响应映射到我的 java bean -PolicyHolderBean,它复制了 JSON 响应的结构。
在 PolicyholdersControllers 中,我调用另一个控制器 -authorizationTokenController-,它也返回带有令牌的 JSON。它以与 PolicyHoldersControllerworks 相同的方式实现并且工作正常,所以我很困惑为什么我的浏览器中的 PolicyHoldersController 为空。我错过了什么吗?
PolicyHolders控制器:
@RestController
public class PolicyHoldersController {
private HttpHeaders setHeaders() {
AuthorizationTokenController authorizationTokenController =
new AuthorizationTokenController();
AuthorizationTokenBean authorizationTokenBean =
authorizationTokenController.postAuthorizationToken();
HttpHeaders headers = new HttpHeaders();
headers.add("Authorization", authorizationTokenBean.getAuthorizationToken());
headers.add("accept", "application/json");
return headers;
}
@GetMapping("/policyholders")
public PolicyHolderBean getPolicyHolders() {
HttpEntity<String> request =
new HttpEntity<String>(setHeaders());
ResponseEntity<PolicyHolderBean> responseEntity = new RestTemplate().exchange(
"https://api.acmeinsurance.com/policyholders",
HttpMethod.GET,
request,
PolicyHolderBean.class
);
PolicyHolderBean policyholders = responseEntity.getBody();
return policyholders;
}
PolicyHolderBean:
public class PolicyHolderBean {
private PolicyHolderResponse3Bean[] policyholders;
public PolicyHolderBean() {
}
public PolicyHolderBean(PolicyHolderResponse3Bean[] policyholders) {
this.policyholders = policyholders;
}
public PolicyHolderResponse3Bean[] getPolicyHolders() {
return policyholders;
}
public void setPolicyHolders(PolicyHolderResponse3Bean[] policyholders) {
this.policyholders = policyholders;
}
}
犯罪嫌疑人X
HUWWW
相关分类