spring-projects / spring-projects/spring-data-rest
[item resource : update ] :Possible bug or documentation not conform [DATAREST-728]
@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
Sylvain LB opened DATAREST-728 and commented
Hello Oliver,
I am facing a small issue while I am trying to update a resource, which contains sub-resources.
Considering my following entity :
@Entity
@Table(name = "USER")
public class User implements Serializable {
/**
*
*/
private static final long serialVersionUID = 4038037527581624919L;
@Id
@GeneratedValue
@Column(name = "ID")
private long id;
@NotNull
@Column(name = "USERNAME", unique = true, nullable = false)
@Size(min = 3, max = 25)
private String username;
@Column(name = "NOM", nullable = false)
private String nom;
@Column(name = "PRENOM", nullable = false)
private String prenom;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "ID_ROLE", nullable = false, referencedColumnName = "ID")
private Role role;
public Role getRole() {
return role;
}
public void setRole(Role role) {
this.role = role;
}
public Country getCountry() {
return country;
}
public void setCountry(Country country) {
this.country = country;
}
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "ID_COUNTRY", nullable = false, referencedColumnName = "ID")
private Country country;
1/ To update my entity users with sub-resources (role or country), I have to do this HTTP request:
PATCH http://localhost:8080/users/1 with content-type "application/patch+json"
with this payload
{
"nom":"test1",
"prenom": "test2",
"username":"test3",
"country": {
"id" :"1"
},
"role": {
"id" :"2"
}
}
In this case, everything works fine : HTTP STATUS 200 OK
2/ If I do the same thing, but with the PUT method with the content-type "application/json", I've got an error (409 CONFLICT - "NULL not allowed for column "ID_COUNTRY), which is right for me.
PUT http://localhost:8080/users/1 with content-type "application/json"
3/ But If I do this , everything works fines, whereas I think I should get an error.
PUT http://localhost:8080/users/1 with content-type "application/patch+json"
I don't know if it's really a bug or something incomplete in the documentation, because I don't know really what is the behavior expected in this case.
When I read the documentation, the only content-type supported for an update of an item resource with PUT method are :
- application/hal+json
- application/json
Either, you just miss to add this content-type "application/patch+json" for PUT method in the documentation. Or, "application/patch+json" should not be supported with PUT method, which makes sense for me (the content-type "application/patch+json" doesn't match the PUT method) and I shouldn't get a 200 status code.
What do you think ?
Thank you,
Sylvain
Affects: 2.4.1 (Gosling SR1)
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.