1
好的,我遇到的問題是我可以使用RestTemplate成功完成後調用。請求在服務器端成功完成。Spring RestTemplate響應值全爲空
但是,當它在客戶端進行設置時,值無法正確分配。下面的第一個類是應由Post調用填充的客戶端。第二類是服務器用來發送它的類。
我相信我的問題出現是因爲服務器發送的JSON格式。它看起來像下面。
{ "record":{"firstName":"Bill", "lastName":"Johnson", "role":6}}
Spring不能自動將其映射到客戶端POJO。有沒有辦法改變服務器端代碼?
謝謝。
EmployeeResponse response = restTemplate.postForObject(uri, request, EmployeeResponse.class);
//(Client Side)
public class EmployeeResponse {
private String firstName;
private String lastName;
private int role;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName= firstName;
}
public String getLastName() {
return longKey;
}
public void setLastName(String lastName) {
this.lastName= lastName;
}
public int getRole() {
return role;
}
public void setRole(int role) {
this.role = role;
}
}
//(Server-Side)
public class EmployeeResponse {
private EmployeeRecord record;
public String getFirstName() {
return record.getFirstName();
}
public String getLastName() {
return record.getLastName();
}
public int getRole() {
return record.getRole();
}
public ELAActivationResponse(EmployeeRecord record) {
this.record = record;
}
}