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

No uri to Entity translation when using @JsonCreator [DATAREST-993]

Open
#1,304 1 comment 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

Benjamin Legendre opened DATAREST-993 and commented

It doesn't seems to be possible to make use of @JsonCreator with an argument of type "association entity", when this association is given in uri form on a POST request.

Simple example:

public class Parent {}

public class Child {

    private String name;

    @ManyToOne
    private Parent parent;

    @JsonCreator
    public Child ( @JsonProperty("name") String name, @JsonProperty("parent") Parent parent ) {
           this.name = name;
           this.parent = parent;
    }

}

When a POST request like this is sent:

POST /childs // or children?, this is only for example

{
      "name": "foo",
      "parent": "http://localhost/parents/1"
}

The error exception bellow is thrown:

2017-01-31 12:52:10.403 ERROR 28343 --- [ main] o.s.d.r.w.RepositoryRestExceptionHandler : Could not read document: Can not construct instance of org.project.Child: no String-argument constructor/factory method to deserialize from String value ('http://localhost/parents/1')

If not using @JsonCreator but by the way of traditionnal setters it works as expected (ie: the Parent entity is correctly set).

It seems there is some SDR internals @JsonDeserializers which are not applied when using @JsonCreator.


Affects: 2.5.6 (Hopper SR6), 2.6 GA (Ingalls)

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.