DATAREDIS-1179 - Allow reuse of RedisConverter in ObjectHashMapper.
Original pull request: #548.
This commit is contained in:
committed by
Mark Paluch
parent
f92ed7632d
commit
59065ab0bc
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user