spring-projects / spring-projects/spring-data-rest
Add mapping for converted objects [DATAREST-533]
@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
Vasily Kartashov opened DATAREST-533 and commented
I have an entity with an embedded object that is stored as a serialised JSON in the database:
@Entity
public class Unit {
...
@Column
@Convert(converter = ConnectionStatusConverter.class)
private ConnectionStatus connectionStatus;
...
}
@Converter
public class ConnectionStatusConverter implements AttributeConverter<ConnectionStatus, String> {
public String convertToDatabaseColumn(ConnectionStatus attribute) { ... }
public ConnectionStatus convertToEntityAttribute(String dbData) { ... }
}
Everything is fine with serialisation and deserialisation except when I try to PATCH an object with the following payload
{
"connectionStatus": {
...
}
}
I get NullPointerException. It is caused by the DomainObjectReader.doMerge expecting embedded object to be an entity, and this one (of type ConnectionStatus) is obviously not.
The solution maybe fairly simple, unless I badly misjudge the code: As long as the entity's property is marked with @Column don't try to find an embedded entity, but stick with current one (in my case Unit) while merging the fields.
Affects: 2.3 GA (Fowler)
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.