spring-projects / spring-projects/spring-data-rest
Rest Endpoint produces HttpMessageNotWritableException [DATAREST-1047]
@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
Henri Sara opened DATAREST-1047 and commented
A simple project accessing a Spring Data repository through REST results in a ClassCastException from Jackson, which is using the wrong serializer (DoubleSerializer for a String) in BeanPropertyWriter.serializeAsField().
The symptoms resemble the old issues DATAREST-716 and DATAREST-743.
The linked GitHub project (branch spring-data-bug) produces the error when using 2.0.0.BUILD-SNAPSHOT as the sprint-boot-starter-parent version but not with 1.5.2.RELEASE when accessing the root of the REST endpoint ( http://localhost:8080/beverage/ ).
The output is
Could not write content: java.lang.String cannot be cast to java.lang.Double (through reference chain: org.springframework.hateoas.PagedResources["_embedded"]->java.util.Collections$UnmodifiableMap["beverages"]->java.util.ArrayList[0]->org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module$PersistentEntityResourceSerializer$1["content"]->com.example.Beverage["beverageName"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: java.lang.String cannot be cast to java.lang.Double (through reference chain: org.springframework.hateoas.PagedResources["_embedded"]->java.util.Collections$UnmodifiableMap["beverages"]->java.util.ArrayList[0]->org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module$PersistentEntityResourceSerializer$1["content"]->com.example.Beverage["beverageName"])
Affects: 3.0 M2 (Kay)
Reference URL: https://github.com/hesara/cologne-jug/tree/spring-data-bug
2 votes, 3 watchers
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.