3434
3535import org .springframework .data .annotation .Id ;
3636import org .springframework .data .annotation .Reference ;
37+ import org .springframework .data .annotation .TypeAlias ;
3738import org .springframework .data .geo .Point ;
3839import org .springframework .data .keyvalue .annotation .KeySpace ;
3940import org .springframework .data .redis .connection .RedisConnection ;
@@ -62,6 +63,7 @@ public class RedisKeyValueAdapterTests {
6263 private RedisKeyValueAdapter adapter ;
6364 private StringRedisTemplate template ;
6465 private RedisConnectionFactory connectionFactory ;
66+ private RedisMappingContext mappingContext ;
6567
6668 public RedisKeyValueAdapterTests (RedisConnectionFactory connectionFactory ) throws Exception {
6769 this .connectionFactory = connectionFactory ;
@@ -73,7 +75,7 @@ void setUp() {
7375 template = new StringRedisTemplate (connectionFactory );
7476 template .afterPropertiesSet ();
7577
76- RedisMappingContext mappingContext = new RedisMappingContext (
78+ mappingContext = new RedisMappingContext (
7779 new MappingConfiguration (new IndexConfiguration (), new KeyspaceConfiguration ()));
7880 mappingContext .afterPropertiesSet ();
7981
@@ -225,6 +227,34 @@ void getShouldReadNestedObjectCorrectly() {
225227 assertThat (((Person ) loaded ).address .country ).isEqualTo ("Andor" );
226228 }
227229
230+ @ Test // #1995
231+ void getAllOfShouldReturnSuperTypeIfForUnregisteredTypeAlias () {
232+
233+ Map <String , String > map = new LinkedHashMap <>();
234+ map .put ("_class" , "taveren" );
235+ map .put ("address.country" , "Andor" );
236+ template .opsForHash ().putAll ("persons:load-1" , map );
237+
238+ Object loaded = adapter .get ("load-1" , "persons" , Person .class );
239+
240+ assertThat (loaded ).isExactlyInstanceOf (Person .class );
241+ }
242+
243+ @ Test // #1995
244+ void getAllOfShouldReturnCorrectTypeIfForRegisteredTypeAlias () {
245+
246+ mappingContext .getPersistentEntity (TaVeren .class );
247+
248+ Map <String , String > map = new LinkedHashMap <>();
249+ map .put ("_class" , "taveren" );
250+ map .put ("address.country" , "Andor" );
251+ template .opsForHash ().putAll ("persons:load-1" , map );
252+
253+ Object loaded = adapter .get ("load-1" , "persons" , Person .class );
254+
255+ assertThat (loaded ).isExactlyInstanceOf (TaVeren .class );
256+ }
257+
228258 @ Test // DATAREDIS-425
229259 void couldReadsKeyspaceSizeCorrectly () {
230260
@@ -826,6 +856,7 @@ static class AddressWithPostcode extends Address {
826856 String postcode ;
827857 }
828858
859+ @ TypeAlias ("taveren" )
829860 static class TaVeren extends Person {
830861
831862 }
0 commit comments