英文:
Can I use ParameterizedTypeReference to avoid cast
问题
我了解如何使用ParameterizedTypeReference来影响RestTemplate的反序列化,但我也希望返回类型能够动态确定。
ParameterizedTypeReference<List<MyModel>> typeRef = new ParameterizedTypeReference<List<MyModel>>() {};
这是我想要重构的代码行:
ResponseEntity<List<MyModel>> = restTemplate.exchange(... typeRef)
是否有一种形式的restTemplate.setExpectedReturnType(refType)
?
英文:
I understand how to use ParameterizedTypeReference to influence RestTemplate deserialization, however, I would like to also have the return type dynamically determined as well.
ParameterizedTypeReference<List<MyModel>> typeRef = new ParameterizedTypeReference<List<MyModel>>(){};
This the line I'd like to refactor:
ResponseEntity<List<MyModel>> = restTemplate.exchange(... typeRef)
Is there a form of restTemplate.setExpectedReturnType(refType)
?
专注分享java语言的经验与见解,让所有开发者获益!
评论