Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better parameterized type serialization for the request body in RestTemplate [SPR-13154] #17745

Closed
spring-projects-issues opened this issue Jun 22, 2015 · 3 comments
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jun 22, 2015

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:

  • 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

Issue Links:

Referenced from: commits 3329abf

0 votes, 5 watchers

@spring-projects-issues
Copy link
Collaborator Author

Sébastien Deleuze commented

Juergen Hoeller Rossen Stoyanchev Arjen Poutsma Brian Clozel I would be interested by your feedback about one of the choices we have to make here:

  • 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.

Any thoughts?

@spring-projects-issues
Copy link
Collaborator Author

Sébastien Deleuze commented

As discussed during a previous meeting, I have implemented this with a RequestEntity#type property. Draft commit available here (pending review with Arjen Poutsma).

@spring-projects-issues
Copy link
Collaborator Author

Sébastien Deleuze commented

Resolved by this commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants