spring-projects / spring-projects/spring-data-rest
Cannot PATCH an entity, that has an enum set, to increase the number of enums, if 'enum traslation' is enabled [DATAREST-1139]
@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
Sergei Poznanski opened DATAREST-1139 and commented
If an entity has an enum set property, and 'enum traslation' is enabled (spring.data.rest.enable-enum-translation=true), the trying to PATCH this entity, to increase a number of enums in the set, leads to an error:
Could not read payload!; nested exception is java.lang.IllegalStateException: Can only translate enum with property information!
If I update the enum set with the same number of enums (or less) then the entity is updated correctly.
PUT updates the enum set correctly in anyway.
If I turn off the 'enum traslation' then PATCH works as expected.
Example:
@Entity
public class User {
private String name;
@Enumerated(EnumType.STRING)
@CollectionTable(name = "roles", joinColumns = @JoinColumn(name = "user_id"))
@ElementCollection
private Set<Role> roles;
// other stuff
}
public enum Role {
ADMIN, USER, POWER_USER
}
Enum translation:
io.github.cepr0.enumtranslatingissue.Role.ADMIN=Admin
io.github.cepr0.enumtranslatingissue.Role.USER=User
io.github.cepr0.enumtranslatingissue.Role.POWER_USER=Power user
Error:
GET http://localhost:8080/api/users/1
{
"name": "user1",
"roles": [
"Admin",
"User"
],
"_links": {
"self": {
"href": "http://localhost:8080/api/users/1"
},
"user": {
"href": "http://localhost:8080/api/users/1"
}
}
}
PATCH http://localhost:8080/api/users/1
{
"roles": [
"Admin",
"User",
"Power user"
]
}
{
"cause": {
"cause": null,
"message": "Can only translate enum with property information!"
},
"message": "Could not read payload!; nested exception is java.lang.IllegalStateException: Can only translate enum with property information!"
}
Affects: 2.6.7 (Ingalls SR7)
Reference URL: https://stackoverflow.com/q/46103203
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.