Skip to content

MappingRedisConverter deserializes collections as nulls if it is empty #2298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Numbedme opened this issue Apr 10, 2022 · 1 comment
Open
Assignees
Labels
status: waiting-for-triage An issue we've not yet triaged

Comments

@Numbedme
Copy link

Numbedme commented Apr 10, 2022

Method readCollectionOrArray creates a collection, although if there are no keys it returns null, which seems kinda strange. Wouldn't it be more client-friendly to return an empty list?
For example:


@RedisHash("Entity")
public class Entity {
    @Id
    private long id;

    @Indexed
    private List<String> props;
}

props will be null on query if it was saved as an empty list

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 10, 2022
@christophstrobl christophstrobl self-assigned this Apr 11, 2022
@Aaur1s
Copy link

Aaur1s commented Mar 25, 2025

Will this ever be fixed? Because of this issue Kotlin data-classes are looking funky if they have possibly empty collection attribute, example:

@RedisHash("access_tokens")
data class AccessToken(
    @Id val id: String,
    val principalName: String,
    val authorizedRoles: Set<String>, // <- deserialization results an error if set is empty
)

This issue requires to write something like this:

@RedisHash("access_tokens")
data class AccessToken(
    @Id val id: String,
    val principalName: String,
    private val _authorizedRoles: Set<String>?,
) {
    val authorizedRoles: Set<String> get() = _authorizedRoles ?: setOf()
}

Very annoying for large entities.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

4 participants