Jackson is not deserialising a generic list that it has serialised

You need to show bit more code, specifically on how you invoke deserialization, but from the error I would guess you are not passing parameterization of T. If it is missing, T can only be assumed to be of type Object, and nominal type of Object is bound to “native” Java type, which for JSON objects is Map (and specifically, LinkedHashMap to preserve order).

So you probably just need to specify generic type of object on deserialization (for serialization it is not needed as runtime type is available); either by using TypeReference (not plain Class, since that has no generic type info), or by constructing generic-enabled JavaType. For example:

NSResponse<CheckStatusDetail> resp = mapper.readValue(json, new TypeReference<NSResponse<CheckStatusDetail>>() { });

or

NSResponse<CheckStatusDetail> resp = mapper.readValue(json, TypeFactory.genericType(NSResponse.class, CheckStatusDetails.class));

both work; latter is necessary if type is only dynamically available.

Leave a Comment