I am trying to convert a Map to Map. I have a json and Object :
{
A: { availableInfo: { isAvailable : true} },
VV: { availableInfo: { isAvailable : false} },
B45: { availableInfo: { isAvailable : null} }
}
And the Object :
@Builder
@Getter
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class AvailableInfo {
@JsonProperty("isAvailable")
private Boolean isAvailable;
public AvailableInfo() {
}
}
I tried :
Map<String, AvailableInfo> response = getResponse(query, Map.class);
But I am getting Error:
java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to AvailableInfo
Below is the getResponse() method :
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>
}
Any idea how it can be resolved? I tried changing the input json to :
{
A: { isAvailable : true} ,
VV: { isAvailable : false} ,
B45: { isAvailable : null}
}
But still not working.