spring-projects / spring-projects/spring-data-rest

PersistentEntityResourceHandlerMethodArgumentResolver should honour custom converters [DATAREST-1582]

Open
#1,941 0 comments 1 reaction 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

type: enhancement
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:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.