34
34
35
35
import org .springframework .data .annotation .Id ;
36
36
import org .springframework .data .annotation .Reference ;
37
+ import org .springframework .data .annotation .TypeAlias ;
37
38
import org .springframework .data .geo .Point ;
38
39
import org .springframework .data .keyvalue .annotation .KeySpace ;
39
40
import org .springframework .data .redis .connection .RedisConnection ;
@@ -62,6 +63,7 @@ public class RedisKeyValueAdapterTests {
62
63
private RedisKeyValueAdapter adapter ;
63
64
private StringRedisTemplate template ;
64
65
private RedisConnectionFactory connectionFactory ;
66
+ private RedisMappingContext mappingContext ;
65
67
66
68
public RedisKeyValueAdapterTests (RedisConnectionFactory connectionFactory ) throws Exception {
67
69
this .connectionFactory = connectionFactory ;
@@ -73,7 +75,7 @@ void setUp() {
73
75
template = new StringRedisTemplate (connectionFactory );
74
76
template .afterPropertiesSet ();
75
77
76
- RedisMappingContext mappingContext = new RedisMappingContext (
78
+ mappingContext = new RedisMappingContext (
77
79
new MappingConfiguration (new IndexConfiguration (), new KeyspaceConfiguration ()));
78
80
mappingContext .afterPropertiesSet ();
79
81
@@ -225,6 +227,34 @@ void getShouldReadNestedObjectCorrectly() {
225
227
assertThat (((Person ) loaded ).address .country ).isEqualTo ("Andor" );
226
228
}
227
229
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
+
228
258
@ Test // DATAREDIS-425
229
259
void couldReadsKeyspaceSizeCorrectly () {
230
260
@@ -826,6 +856,7 @@ static class AddressWithPostcode extends Address {
826
856
String postcode ;
827
857
}
828
858
859
+ @ TypeAlias ("taveren" )
829
860
static class TaVeren extends Person {
830
861
831
862
}
0 commit comments