[QUESTION]CommonResponse<List<T>> 如何使用 TypeReference
- Dominant language
- Java
- Stars
- 4.4k
- Forks
- 613
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 6
Description
### 请描述您的问题
*询问有关本项目的使用和其他方面的相关问题。*
有一个泛型结合问题想请教一下
#### CommonResponse 统一响应类
```java
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CommonResponse {
private Integer code;
private T data;
private String msg;
public S getTypeData(TypeReference typeReference) {
return JSON.parseObject(JSON.toJSONString(data), typeReference);
}
```
#### 业务层
```java
...
// confirmOrderCartItems这个接口得到的 CommonResponse data 类型就是 List
CommonResponse cartItemResponse = productFeignService.confirmOrderCartItems(productIdList);
// 想通过 getTypeData 自动识别为 List,但是报错了
List orderItemVOList = cartItemResponse.getTypeData(new TypeReference<>() {
});
```
使用了 Feign 做微服务调用,目前是两个微服务之间调用了

求助,这里应该怎么改?google了一圈,找到类似解决方案,但是放在我这还是报错了
Contributor guide
Research direction
Start with the CommonResponse getTypeData method and the business-layer call using TypeReference>. Reproduce the Feign response conversion and inspect the reported exception, which is not included here. Done means identifying the generic deserialization issue and confirming a working way to obtain the list.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 15/100