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

Add mapping for converted objects [DATAREST-533]

Open
#908 6 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

in: repository type: enhancement
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

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.