osigge
osigge

Reputation: 228

Spring Data Redis Repository support does not read back embedded complex objects

I have a spring-boot application (1.4RC1, I know it's RC, but Spring Data Redis 1.7.2 is not) where I'm using spring-boot-starter-redis.

The application uses a Spring Data Repository (CrudRepository) which should save an object (using @RedisHash annotation) with String and Boolean properties and one custom class property, which also has only Strings and Longs as properties.

When I save an object (via the repository), everything went fine and I can see all the properties in the database as I would expect. When I want to read the data from the database (via the repository) I only get the properties from the parent object. The custom class property is null.

I would expect to get the property loaded from the database as well. As the documentation states you can write a custom converter, but since I don't need to do that, when I want to write the data, I shouldn't need to write a reading converter as well.

I wonder if I need to annotate the custom class property, but I couldn't find anything in the documentation. Can you point me in the right direction?

The classes are as follows:

Class sample:

@Data
@EqualsAndHashCode(exclude = {"isActive", "sampleCreated", "sampleConfiguration"})
@RedisHash
public class Sample {

    @Id
    private String sampleIdentifier;

    private Boolean isActive;

    private Date sampleCreated;

    private SampleConfiguration sampleConfiguration;

    public Sample(String sampleIdentifier, SampleConfiguration sampleConfiguration){
        this.sampleIdentifier = sampleIdentifier;
        this.sampleConfiguration = sampleConfiguration;
    }

}

Class SampleConfiguration:

@Data
public class SampleConfiguration {

    private String surveyURL;

    private Long blockingTime;

    private String invitationTitle;

    private String invitationText;

    private String participateButtonText;

    private String doNotParticipateButtonText;

    private String optOutButtonText;

    private Long frequencyCappingThreshold;

    private Long optOutBlockingTime;

}

Upvotes: 3

Views: 1852

Answers (1)

osigge
osigge

Reputation: 228

I added @NoArgsConstructor to my Sample class as Christoph Strobl suggested. Then the repository reads the SampleConfiguration correctly. Thanks, Christoph!

Upvotes: 4

Related Questions