具有通用responseType的通用restTemplateExchange
我想创建一个自己的通用方法来调用restTemplate.exchange。 特别是,我希望这个通用方法的签名是:
protected <T> ResponseEntity<T> genericExchange(String uri, HttpMethod method, @Nullable HttpEntity<?> requestEntity, -->responseType<--)
我将根据“responseType”区分 exchange 方法调用
- 如果 responseType 是 Class, 我调用*交换(URI url, HttpMethod method, HttpEntity requestEntity, Class
responseType)* - 。 T>如果responseType是ParameterizedTypeReference, T> 我调用*交换(URI url, HttpMethod method, HttpEntity requestEntity, ParameterizedTypeReference< T> responseType)*
I would like to create a own generic method that calls the restTemplate.exchange.
In particular I would like that the signature of this generic method to be :
protected <T> ResponseEntity<T> genericExchange(String uri, HttpMethod method, @Nullable HttpEntity<?> requestEntity, -->responseType<--)
I would differentiate what exchange method call according to "responseType"
- if responseType is Class< T> I call * exchange(URI url, HttpMethod method, HttpEntity<?> requestEntity, Class< T> responseType)*
- if responseType is ParameterizedTypeReference< T> I call * exchange(URI url, HttpMethod method, HttpEntity<?> requestEntity, ParameterizedTypeReference< T> responseType)*
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了这个答案,它对我有用:
无法获取通用 ResponseEntity;其中 T 是泛型类“SomeClass”
I found this answer, and it was working for me:
Unable to get a generic ResponseEntity<T> where T is a generic class "SomeClass<SomeGenericType>"