使用 Jackson 序列化后,通过TypeFactory工厂创建CollectionType
代码语言:javascript复制public static <T> List<T> transToList(Object data, Class<T> clazz) throws JsonProcessingException {
CollectionType collectionType = OBJECT_MAPPER.getTypeFactory().constructCollectionType(List.class, clazz);
String asString = OBJECT_MAPPER.writeValueAsString(data);
return OBJECT_MAPPER.readValue(asString, collectionType);
}
详见:Jackson 反序列化 Map 集合