DATAREDIS-909 - Fix constructor creation of entities with collection-typed properties.
We now consider the property type in value conversion for constructor arguments to provide the appropriate value type. Previously, we considered the component type which converted a Collection<T> to a single T that caused downstream ClassCastException. Original Pull Request: #378
This commit is contained in:
committed by
Christoph Strobl
parent
1f4bb973ea
commit
d248c0cd7c
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.redis.core.convert;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@@ -31,6 +32,7 @@ import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
@@ -213,4 +215,11 @@ public class ConversionTestEntities {
|
||||
Map<Double, String> decimalMapKeyMapping;
|
||||
Map<Date, String> dateMapKeyMapping;
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
static class Device {
|
||||
|
||||
final Instant now;
|
||||
final Set<String> profiles;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1472,6 +1472,18 @@ public class MappingRedisConverterUnitTests {
|
||||
assertThat(result.list.get(2), instanceOf(Date.class));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-909
|
||||
public void shouldWriteReadObjectWithConstructorConversion() {
|
||||
|
||||
Device sample = new Device(Instant.now(), Collections.singleton("foo"));
|
||||
|
||||
RedisData rd = write(sample);
|
||||
|
||||
Device result = converter.read(Device.class, rd);
|
||||
assertThat(result.now, equalTo(sample.now));
|
||||
assertThat(result.profiles, equalTo(sample.profiles));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-509
|
||||
public void writeHandlesArraysOfPrimitivesProperly() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user