我正在尝试将JSON字符串反序列化为MyClass列表,但遇到此异常:
VALUE_STRING令牌中的 java.util.ArrayList;嵌套异常是com.fasterxml.jackson.databind.exc.MismatchedInputException:无法从VALUE_STRING令牌中反序列化java.util.ArrayList
实例
MyClass对于从服务器中获取的JSON字符串中的每个属性都有一个公共字符串获取器/设置器:
[{“ PublicIP”:“ 1.1.1.1”,“ PrivateIP”:“ 1.1.1.1”,“ InstanceId”:“ i-1234”,“ IsRunning”:false}]
以下是调用服务器的代码:
ResponseEntity<List<MyClass>> response =
restTemplate.exchange("http://localhost:5000/api/cloud/thelist",
HttpMethod.GET, null,
new ParameterizedTypeReference<List<MyClass>>() {});
这是MyClass bean:
public class MyClass {
private String PublicIP;
private String PrivateIP;
private String InstanceId;
private boolean IsRunning;
public String getPublicIP() {
return PublicIP;
}
public void setPublicIP(String publicIP) {
PublicIP = publicIP;
}
public String getPrivateIP() {
return PrivateIP;
}
public void setPrivateIP(String privateIP) {
PrivateIP = privateIP;
}
public String getInstanceId() {
return InstanceId;
}
public void setInstanceId(String instanceId) {
InstanceId = instanceId;
}
public boolean isIsRunning() {
return IsRunning;
}
public void setIsRunning(boolean isRunning) {
IsRunning = isRunning;
}
}
返回字符串是一个List,并且我还有setter方法。我是否缺少一些配置,以告知如何反序列化此对象?