DATAREDIS-955 - Fix collection initialization when reading nested structures with same name.

We now make sure to not falsely populate instances with null values from nested structures.

Original pull request: #452.
This commit is contained in:
Christoph Strobl
2019-05-21 12:20:45 +02:00
committed by Mark Paluch
parent b09679675f
commit 4378669d33
3 changed files with 39 additions and 1 deletions

View File

@@ -158,7 +158,7 @@ public class Bucket {
return keySet();
}
Pattern pattern = Pattern.compile("(" + Pattern.quote(path) + ")\\.\\[.*?\\]");
Pattern pattern = Pattern.compile("^(" + Pattern.quote(path) + ")\\.\\[.*?\\]");
Set<String> keys = new LinkedHashSet<String>();
for (Map.Entry<String, byte[]> entry : data.entrySet()) {

View File

@@ -192,4 +192,15 @@ public class ConversionTestEntities {
Map<Double, String> decimalMapKeyMapping;
Map<Date, String> dateMapKeyMapping;
}
static class Outer {
List<Inner> inners;
List<String> values;
}
static class Inner {
List<String> values;
}
}

View File

@@ -1752,6 +1752,33 @@ public class MappingRedisConverterUnitTests {
assertThat(write(update).getBucket().get("_class"), is(nullValue()));
}
@Test // DATAREDIS-955
public void readInnerListShouldNotInfluenceOuterWithSameName() {
Map<String, String> source = new LinkedHashMap<String, String>();
source.put("inners.[0].values.[0]", "i-1");
source.put("inners.[0].values.[1]", "i-2");
source.put("values.[0]", "o-1");
source.put("values.[1]", "o-2");
Outer outer = read(Outer.class, source);
assertThat(outer.values, is(equalTo(Arrays.asList("o-1", "o-2"))));
assertThat(outer.inners.get(0).values, is(equalTo(Arrays.asList("i-1", "i-2"))));
}
@Test // DATAREDIS-955
public void readInnerListShouldNotInfluenceOuterWithSameNameWhenNull() {
Map<String, String> source = new LinkedHashMap<String, String>();
source.put("inners.[0].values.[0]", "i-1");
source.put("inners.[0].values.[1]", "i-2");
Outer outer = read(Outer.class, source);
assertThat(outer.values, is(nullValue()));
assertThat(outer.inners.get(0).values, is(equalTo(Arrays.asList("i-1", "i-2"))));
}
private RedisData write(Object source) {
RedisData rdo = new RedisData();