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

Rest Endpoint produces HttpMessageNotWritableException [DATAREST-1047]

Open
#1,414 2 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

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

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.