【发布时间】:2020-05-28 13:20:13
【问题描述】:
我一直在尝试许多解决此页面中类似已解决问题的解决方案,但我无法使其发挥作用。我正在发出请求以获取数组 JSON,并且我想将这些值映射到我的类中。
我上了这门课:
public class Devices {
private String DeviceName;
private String DeviceDescription;
public String getDeviceName() {
return DeviceName;
}
public void setDeviceName(String deviceName) {
this.DeviceName = deviceName;
}
public String getDeviceDescription() {
return DeviceDescription;
}
public void setDeviceDescription(String deviceDescription) {
this.DeviceDescription = deviceDescription;
}
}
GET 请求在下面返回这个 JSON:
[{"DeviceName":"AMIXT-20EC-VIDM0000","DeviceDescription":"Samsung device "},{"DeviceName":"AMIXT-E0F9-VIDM0001","DeviceDescription":"Tablet Huawei"}]
我已经尝试过这样的解决方案(也尝试使用 getForObject):
ResponseEntity<Devices[]> responseEntity = restTemplate.getForEntity(url, Devices[].class);
我们可以看到in this photo,body 属性为空
我错过了什么?
【问题讨论】:
-
您应该关注Java Naming Conventions。它将防止您出现许多类似的问题,因为各种映射库都希望您的 POJO 被正确声明和命名
标签: json spring spring-boot rest resttemplate