DATAREDIS-768 - Consider map key type in MappingRedisConverter.readMap…(…).

We now consider the key type when reading a map from a Redis Hash. Previously, map keys were read as string while a map could declare numeric keys.

Original Pull Request: #312
This commit is contained in:
Mark Paluch
2018-02-15 12:21:25 +01:00
committed by Christoph Strobl
parent d6d5b9e610
commit 208f9e12c4
3 changed files with 62 additions and 5 deletions

View File

@@ -57,6 +57,7 @@ public class ConversionTestEntities {
List<String> nicknames;
List<Person> coworkers;
List<Integer> positions;
Integer age;
Boolean alive;
Date birthdate;
@@ -73,7 +74,9 @@ public class ConversionTestEntities {
Address address;
Map<String, String> physicalAttributes;
Map<Integer, Integer> numberMapping;
Map<String, Person> relatives;
Map<Integer, Person> favoredRelatives;
@Reference Location location;
@Reference List<Location> visited;

View File

@@ -275,6 +275,18 @@ public class MappingRedisConverterUnitTests {
assertThat(converter.read(Person.class, rdo).nicknames, contains("dragon reborn", "car'a'carn", "lews therin"));
}
@Test // DATAREDIS-768
public void readConvertsUnorderedListOfSimpleIntegerPropertiesCorrectly() {
Map<String, String> map = new LinkedHashMap<>();
map.put("positions.[9]", "0");
map.put("positions.[10]", "1");
map.put("positions.[1]", "2");
RedisData rdo = new RedisData(Bucket.newBucketFromStringMap(map));
assertThat(converter.read(Person.class, rdo).positions, contains(2, 0, 1));
}
@Test // DATAREDIS-425
public void readComplexPropertyCorrectly() {
@@ -402,6 +414,22 @@ public class MappingRedisConverterUnitTests {
assertThat(target.physicalAttributes.get("eye-color"), is("grey"));
}
@Test // DATAREDIS-768
public void readSimpleIntegerMapValuesCorrectly() {
Map<String, String> map = new LinkedHashMap<>();
map.put("numberMapping.[1]", "2");
map.put("numberMapping.[3]", "4");
RedisData rdo = new RedisData(Bucket.newBucketFromStringMap(map));
Person target = converter.read(Person.class, rdo);
assertThat(target.numberMapping, notNullValue());
assertThat(target.numberMapping.get(1), is(2));
assertThat(target.numberMapping.get(3), is(4));
}
@Test // DATAREDIS-425
public void writeAppendsMapWithComplexObjectsCorrectly() {
@@ -437,6 +465,22 @@ public class MappingRedisConverterUnitTests {
assertThat(target.relatives.get("step-father").firstname, is("tam"));
}
@Test // DATAREDIS-768
public void readMapWithIntegerKeysAndComplexObjectsCorrectly() {
Map<String, String> map = new LinkedHashMap<>();
map.put("favoredRelatives.[1].firstname", "janduin");
map.put("favoredRelatives.[2].firstname", "tam");
Person target = converter.read(Person.class, new RedisData(Bucket.newBucketFromStringMap(map)));
assertThat(target.favoredRelatives, notNullValue());
assertThat(target.favoredRelatives.get(1), notNullValue());
assertThat(target.favoredRelatives.get(1).firstname, is("janduin"));
assertThat(target.favoredRelatives.get(2), notNullValue());
assertThat(target.favoredRelatives.get(2).firstname, is("tam"));
}
@Test // DATAREDIS-425
public void writeAppendsClassTypeInformationCorrectlyForMapWithComplexObjects() {