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

PATCH a collection throws exception [DATAREST-1041]

Open
#1,407 19 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

Petar Tahchiev opened DATAREST-1041 and commented

Hey guys,

I have the following setup:

public class CategoryEntity {
    @ManyToMany
    private Set<ProductEntitiy> products;
}

now I wrote a test-case that issues a PATCH request to update the collection like this:

mockMvc.perform(patch("http://localhost:8080/categoryEntities/1").content(
                "{ \"products\" : [\"http://localhost:8080/productEntities/1\"]}").accept(
                MediaType.APPLICATION_JSON_UTF8_VALUE).contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)).andDo(print()).andExpect(
                status().isOk());

The results are the following:
Spring Boot 1.5.2.SNAPSHOT= Ingalls SR1 = X
Spring Boot 1.5.1.RELEASE = Ingalls REL = X
Spring Boot 1.5.0.RELEASE = Ingalls REL = X
Spring Boot 1.4.6-SNAPSHOT= Hopper SR8 = X
Spring Boot 1.4.5 RELEASE = Hopper SR8 = X
Spring Boot 1.4.4 RELEASE = Hopper SR7 = X
Spring Boot 1.4.3 RELEASE = Hopper SR6 = X
Spring Boot 1.4.2 RELEASE = Hopper SR5 = V
Spring Boot 1.4.1 RELEASE = Hopper SR3 = V
Spring Boot 1.4.0 RELEASE = Hopper SR2 = V
Spring Boot 1.3.8 RELEASE = Gosling SR5 = V

And every single time the exception is the same:

Body = {"cause":{"cause":null,"message":"Can not construct instance of com.example.ProductEntity: no String-argument constructor/factory method to deserialize from String value ('http://localhost:8080/productEntities/1')\n at [Source: N/A; line: -1, column: -1]"},"message":"Could not read payload!; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of com.example.ProductEntity: no String-argument constructor/factory method to deserialize from String value ('http://localhost:8080/productEntities/1')\n at [Source: N/A; line: -1, column: -1]"}

I have jackson-hibernate5 on the classpath. Also I remember not so long ago the body of the request was like the following:

{ "products" : [1]}

(just the ids not the local url) so I tried that one too, but it failed with all of the versions of spring boot.

I'll provide a test project


8 votes, 13 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.