You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since #17408 make it possible to use parameterized type for writing the response body, it would be nice to be able to do the same for request body in client side use cases.
Since we don't have this information in the method declaration like for server side, the user will have to provide the type explicitly.
The proposal for this:
Retaining the type as an RequestEntity#type property
In RequestEntity.BodyBuilder, adding RequestEntity<T> body(T body, Type type) method
In RestTemplate#doWithRequest(), use RequestEntity#type if defined to get the type information, and call the type-aware canWrite() and write() methods if the message converter implements GenericHttpMessageConverter
We can add a Type type property to HttpEntity to fully describe the (potentially generic) type of the body, with the advantage of avoiding to add a bunch of new methods to RestTemplate
We can keep HttpEntity as it is, and add ParameterizedTypeReference<T> requestType parameter variants to RestTemplate, but this class has already a huge API and combining the existing variants with a new ParameterizedTypeReference<T> requestType parameter is not a free lunch.
As discussed during a previous meeting, I have implemented this with a RequestEntity#type property. Draft commit available here (pending review with Arjen Poutsma).
Sébastien Deleuze opened SPR-13154 and commented
Since #17408 make it possible to use parameterized type for writing the response body, it would be nice to be able to do the same for request body in client side use cases.
Since we don't have this information in the method declaration like for server side, the user will have to provide the type explicitly.
The proposal for this:
RequestEntity#type
propertyRequestEntity.BodyBuilder
, addingRequestEntity<T> body(T body, Type type)
methodRestTemplate#doWithRequest()
, useRequestEntity#type
if defined to get the type information, and call the type-awarecanWrite()
andwrite()
methods if the message converter implementsGenericHttpMessageConverter
Issue Links:
@ResponseBody
method return type available to message convertersReferenced from: commits 3329abf
0 votes, 5 watchers
The text was updated successfully, but these errors were encountered: