DATAREDIS-1179 - Allow reuse of RedisConverter in ObjectHashMapper.

Original pull request: #548.
This commit is contained in:
Christoph Strobl
2020-07-14 13:14:20 +02:00
committed by Mark Paluch
parent f92ed7632d
commit 59065ab0bc
3 changed files with 81 additions and 7 deletions

View File

@@ -17,10 +17,15 @@ package org.springframework.data.redis.mapping;
import static org.assertj.core.api.Assertions.*;
import lombok.Data;
import java.util.Collections;
import java.util.Map;
import org.junit.Test;
import org.springframework.data.annotation.TypeAlias;
import org.springframework.data.redis.core.convert.MappingRedisConverter;
import org.springframework.data.redis.core.mapping.RedisMappingContext;
import org.springframework.data.redis.hash.ObjectHashMapper;
/**
@@ -57,4 +62,29 @@ public class ObjectHashMapperTests extends AbstractHashMapperTest {
String result = objectHashMapper.fromHash(hash, String.class);
}
@Test // DATAREDIS-1179
public void hashMapperAllowsReuseOfRedisConverter/*and thus the MappingContext holding eg. TypeAlias information*/() {
WithTypeAlias source = new WithTypeAlias();
source.value = "val";
Map<byte[], byte[]> hash = new ObjectHashMapper().toHash(source);
RedisMappingContext ctx = new RedisMappingContext();
ctx.setInitialEntitySet(Collections.singleton(WithTypeAlias.class));
ctx.afterPropertiesSet();
MappingRedisConverter mappingRedisConverter = new MappingRedisConverter(ctx, null, null);
mappingRedisConverter.afterPropertiesSet();
ObjectHashMapper objectHashMapper = new ObjectHashMapper(mappingRedisConverter);
assertThat(objectHashMapper.fromHash(hash)).isEqualTo(source);
}
@TypeAlias("_42_")
@Data
static class WithTypeAlias {
String value;
}
}