spring-projects / spring-projects/spring-data-rest
PersistentEntityResourceHandlerMethodArgumentResolver should honour custom converters [DATAREST-1582]
@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
laurinstenz opened DATAREST-1582 and commented
org.springframework.data.rest.webmvc.config.PersistentEntityResourceHandlerMethodArgumentResolver is using a conversion service that does not allow to be extended by custom converters, but I guess it should. Please correct me if I'm wrong.
Steps to Reproduce:
There is an example project in the attachment.
- Start the application:
- Issue a put request:
curl --request PUT \
--url 'http://localhost:8080/myEntities/3734a0e5-46f7-4782-ae87-ecabb33630ab' \
--header 'Content-Type: application/json' \
--data '{}'
- This results in 500 Internal Server Error with the exception
org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [com.example.demo.MyEntityId]
Problem
The defined converter is not picked up by the conversion service of org.springframework.data.rest.webmvc.config.PersistentEntityResourceHandlerMethodArgumentResolver. There is a workaround: I can just define a String constructor or a static factory method (then the org.springframework.core.convert.support.ObjectToObjectConverter takes over and successfully converts the object, see the commented code in com.example.demo.MyEntityId). But I think it would still be better if the converter takes care of it, when defined
Affects: 3.4.1 (2020.0.1)
Attachments:
- demo.zip (111.88 kB)
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.