Skip to content

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

Closed

Description

@spring-projects-issues

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

Activity

  1. spring-projects-issues commented on Jan 27, 2016

    @spring-projects-issues
    CollaboratorAuthor

    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?

  2. spring-projects-issues commented on Feb 22, 2016

    @spring-projects-issues
    CollaboratorAuthor

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

  3. spring-projects-issues commented on Feb 23, 2016

    @spring-projects-issues
    CollaboratorAuthor

    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

Metadata

Metadata

Assignees

Labels

type: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions