我正在尝试将地图转换为地图。我有一个 json 和 Object :
{
A: { availableInfo: { isAvailable : true} },
VV: { availableInfo: { isAvailable : false} },
B45: { availableInfo: { isAvailable : null} }
}
和对象:
@Builder
@Getter
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class AvailableInfo {
@JsonProperty("isAvailable")
private Boolean isAvailable;
public AvailableInfo() {
}
}
我试过了 :
Map<String, AvailableInfo> response = getResponse(query, Map.class);
但我收到错误:
java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to AvailableInfo
下面是 getResponse() 方法:
private <T> T getResponse(final RestURI query, final Class<T> responseClass) throws IOException {
T response = null;
final RestResponse<Record> tempResponse = client.call(GET, query);
if (isResponseOK(tempResponse, query)) {
byte[] payloads = {};
for (Record rec : tempResponse.getResponses()) {
final byte[] payload = rec.getPayload();
payloads = ArrayUtils.addAll(payloads, payload);
}
final Reader reader = newReader(payloads)
response = jsonObjectMapper.readValue(reader, responseClass);
}
return response; //returns Map<String, LinkedHashMap>
}
知道如何解决吗?我尝试将输入 json 更改为:
{
A: { isAvailable : true} ,
VV: { isAvailable : false} ,
B45: { isAvailable : null}
}
但仍然无法正常工作。
Helenr
慕妹3242003
相关分类