Skip to content

Fixes #3179 – Restore _class metadata for collections in MappingRedisConverter #3188

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
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ public void write(@Nullable Object source, RedisData sink) {
}

if (source instanceof Collection collection) {
typeMapper.writeType(ClassUtils.getUserClass(source), sink.getBucket().getPath());
writeCollection(sink.getKeyspace(), "", collection, TypeInformation.of(Object.class), sink);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import org.springframework.data.redis.core.mapping.RedisMappingContext;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.test.util.RedisTestData;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;

import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
Expand Down Expand Up @@ -1994,16 +1995,22 @@ void readGenericEntity() {
assertThat(generic.entity.name).isEqualTo("hello");
}

@Test // GH-2168
@Test // GH-2168, GH-3179
void writePlainList() {

List<Object> source = Arrays.asList("Hello", "stream", "message", 100L);
RedisTestData target = write(source);

assertThat(target).containsEntry("[0]", "Hello") //
.containsEntry("[1]", "stream") //
.containsEntry("[2]", "message") //
.containsEntry("[3]", "100");
Object classValue = target.getBucket().get("_class");

assertThat(classValue)
.as("_class metadata should be written")
.isNotNull()
.isInstanceOf(byte[].class);
assertThat(new String((byte[]) classValue, StandardCharsets.UTF_8))
.isEqualTo(ClassUtils.getUserClass(source).getName());
assertThat(target).containsEntry("[0]", "Hello")
.containsEntry("[1]", "stream")
.containsEntry("[2]", "message")
.containsEntry("[3]", "100");
}

@Test // DATAREDIS-1175
Expand Down