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:
committed by
Christoph Strobl
parent
d6d5b9e610
commit
208f9e12c4
@@ -15,10 +15,10 @@
|
||||
*/
|
||||
package org.springframework.data.redis.core.convert;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.*;
|
||||
@@ -844,9 +844,14 @@ public class MappingRedisConverter implements RedisConverter, InitializingBean {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Cannot extract map value for key '%s' in path '%s'.", entry.getKey(), path));
|
||||
}
|
||||
String key = matcher.group(2);
|
||||
Object key = matcher.group(2);
|
||||
|
||||
Class<?> typeToUse = getTypeHint(path + ".[" + key + "]", source.getBucket(), valueType);
|
||||
|
||||
if (!keyType.isAssignableFrom(key.getClass())) {
|
||||
key = conversionService.convert(key, keyType);
|
||||
}
|
||||
|
||||
target.put(key, fromBytes(entry.getValue(), typeToUse));
|
||||
}
|
||||
|
||||
@@ -879,7 +884,7 @@ public class MappingRedisConverter implements RedisConverter, InitializingBean {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Cannot extract map value for key '%s' in path '%s'.", key, path));
|
||||
}
|
||||
String mapKey = matcher.group(2);
|
||||
Object mapKey = matcher.group(2);
|
||||
|
||||
Bucket partial = source.getBucket().extract(key);
|
||||
|
||||
@@ -888,8 +893,13 @@ public class MappingRedisConverter implements RedisConverter, InitializingBean {
|
||||
partial.put(TYPE_HINT_ALIAS, typeInfo);
|
||||
}
|
||||
|
||||
Object o = readInternal(key, valueType, new RedisData(partial));
|
||||
target.put(mapKey, o);
|
||||
if (!keyType.isAssignableFrom(mapKey.getClass())) {
|
||||
mapKey = conversionService.convert(mapKey, keyType);
|
||||
}
|
||||
|
||||
Object value = readInternal(key, valueType, new RedisData(partial));
|
||||
|
||||
target.put(mapKey, value);
|
||||
}
|
||||
|
||||
return target.isEmpty() ? null : target;
|
||||
|
||||
Reference in New Issue
Block a user