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

PUT-request with application/json media type payload cannot update association @OneToOne by URI [DATAREST-1061]

Open
#1,426 4 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

type: bug type: task
Dominant language
Java
Stars
958
Forks
568
PR merge metrics
No merged PRs in 30d

Description

Dmitry Stolbov opened DATAREST-1061 and commented

PUT-request with application/json media type payload cannot update @OneToOne association by URI.
Code works in Spring Boot 1.4.3.Release and does not work from 1.4.4.Release.

POST-request with URI in payload creates @OneToOne association in all versions of Spring Boot from 1.4.3 to 1.5.3.
The test project explains this issue. To reproduce this case you should change spring-boot-starter-parent version in pom.xml.

The tests below illustrate the essence of this issue:

MvcResult resultPost = mockMvc.perform(post("/rest/api/persons?projection=full")
  .contentType(APPLICATION_JSON_UTF8)
  .content("{\"name\": \"Vasiliy\", \"adress\": \"/rest/api/adresses/2\"}"))
  .andExpect(status().isCreated())
  .andReturn();
String location = resultPost.getResponse().getHeader("Location");
Long id = Long.parseLong(location.substring(location.lastIndexOf("/")+1));

mockMvc.perform(get("/rest/api/persons/"+id+"?projection=full"))
  .andExpect(status().isOk())
  .andExpect(jsonPath("id").value(id))
  .andExpect(jsonPath("name").value("Vasiliy"))
  .andExpect(jsonPath("adress.id").value(2))
  .andExpect(jsonPath("adress.city").value("Surgut"));

//FixMe Code works in Spring Boot 1.4.3.Release and does not work from 1.4.4.Release.
mockMvc.perform(put("/rest/api/persons/"+id+"?projection=full")
  .contentType(APPLICATION_JSON_UTF8)
  .content("{\"name\": \"Maria\", \"adress\": \"/rest/api/adresses/4\"}"))
  .andExpect(status().isNoContent());

mockMvc.perform(get("/rest/api/persons/"+id+"?projection=full"))
  .andExpect(status().isOk())
  .andExpect(jsonPath("id").value(id))
  .andExpect(jsonPath("name").value("Maria"))
  .andExpect(jsonPath("adress.id").value(4))
  .andExpect(jsonPath("adress.city").value("Nefteugansk"));

Affects: 2.5.8 (Hopper SR8)

Reference URL: https://github.com/stolbovd/spring-data-examples/blob/master/src/test/java/ru/inkontext/rest/PutOneToOneTest.java

2 votes, 4 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.