spring-projects / spring-projects/spring-data-rest
Extend integration with Spring Web for updating entities beyond the URL Encoded Form media type [DATAREST-1444]
@odrotbohm is already working on this.
Since Dec 31, 2020.
- Dominant language
- Java
- Stars
- 958
- Forks
- 568
- PR merge metrics
- No merged PRs in 30d
Description
Behrang Saeedzadeh opened DATAREST-1444 and commented
According to Spring Data JPA: How to update a model elegantly?, when an appropriate URL Encoded Form Data payload is sent to the following action handler:
@RequestMapping(
value = "/users/{user}",
method = RequestMethod.PATCH
)
public … updateUser(@ModelAttribute User user) { … }
The following steps happen:
An instance of User needs to be obtained. This basically requires a Converter from String to User to be registered with Spring MVC to convert the path segment extracted from the URI template into a User. If you're e.g. using Spring Data and enable its web support as described in its reference documentation, this will work out of the box.
- After the existing instance was obtained, request data will be bound to the existing object.
- The bound object will be handed into the method.
This works only with URL Encoded Form Data. However nowadays it is very common for REST services to consume JSON, XML, and other media types too.
It would be nice if this feature was extended so that it could work with other media types too, probably by integrating with Jaxb2RootElementHttpMessageConverter, MappingJackson2XmlHttpMessageConverter, and other converters.
For more information please see:
- http://stackoverflow.com/questions/41319350/how-to-write-a-restcontroller-to-update-a-jpa-entity-from-an-xml-request-the-sp
- https://github.com/behrangsa/howto-springdata/tree/spring-boot-bug-report
Reference URL: https://github.com/spring-projects/spring-boot/issues/7754
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.