|
56 | 56 | import org.springframework.data.redis.core.mapping.RedisPersistentProperty;
|
57 | 57 | import org.springframework.data.redis.util.ByteUtils;
|
58 | 58 | import org.springframework.data.util.ClassTypeInformation;
|
| 59 | +import org.springframework.data.util.ProxyUtils; |
59 | 60 | import org.springframework.data.util.TypeInformation;
|
60 | 61 | import org.springframework.lang.Nullable;
|
61 | 62 | import org.springframework.util.Assert;
|
@@ -258,12 +259,20 @@ private <R> R doReadInternal(String path, Class<R> type, RedisData source) {
|
258 | 259 | protected Object readProperty(String path, RedisData source, RedisPersistentProperty persistentProperty) {
|
259 | 260 |
|
260 | 261 | String currentPath = !path.isEmpty() ? path + "." + persistentProperty.getName() : persistentProperty.getName();
|
| 262 | + TypeInformation<?> typeInformation = typeMapper.readType(source.getBucket().getPropertyPath(currentPath), |
| 263 | + persistentProperty.getTypeInformation()); |
261 | 264 |
|
262 |
| - TypeInformation<?> typeInformation = persistentProperty.getTypeInformation(); |
| 265 | + if (typeInformation.isMap()) { |
263 | 266 |
|
264 |
| - if (persistentProperty.isMap()) { |
| 267 | + Class<?> mapValueType = null; |
265 | 268 |
|
266 |
| - Class<?> mapValueType = persistentProperty.getMapValueType(); |
| 269 | + if (typeInformation.getMapValueType() != null) { |
| 270 | + mapValueType = typeInformation.getMapValueType().getType(); |
| 271 | + } |
| 272 | + |
| 273 | + if (mapValueType == null && persistentProperty.isMap()) { |
| 274 | + mapValueType = persistentProperty.getMapValueType(); |
| 275 | + } |
267 | 276 |
|
268 | 277 | if (mapValueType == null) {
|
269 | 278 | throw new IllegalArgumentException("Unable to retrieve MapValueType");
|
@@ -293,16 +302,14 @@ protected Object readProperty(String path, RedisData source, RedisPersistentProp
|
293 | 302 | }
|
294 | 303 | }
|
295 | 304 |
|
296 |
| - if (persistentProperty.isEntity() |
| 305 | + if (mappingContext.getPersistentEntity(typeInformation) != null |
297 | 306 | && !conversionService.canConvert(byte[].class, typeInformation.getRequiredActualType().getType())) {
|
298 | 307 |
|
299 | 308 | Bucket bucket = source.getBucket().extract(currentPath + ".");
|
300 | 309 |
|
301 | 310 | RedisData newBucket = new RedisData(bucket);
|
302 |
| - TypeInformation<?> typeToRead = typeMapper.readType(bucket.getPropertyPath(currentPath), |
303 |
| - typeInformation); |
304 | 311 |
|
305 |
| - return readInternal(currentPath, typeToRead.getType(), newBucket); |
| 312 | + return readInternal(currentPath, typeInformation.getType(), newBucket); |
306 | 313 | }
|
307 | 314 |
|
308 | 315 | byte[] sourceBytes = source.getBucket().get(currentPath);
|
@@ -580,8 +587,7 @@ RedisPersistentProperty getTargetPropertyOrNullForPath(String path, Class<?> typ
|
580 | 587 | * @param sink
|
581 | 588 | */
|
582 | 589 | private void writeInternal(@Nullable String keyspace, String path, @Nullable Object value,
|
583 |
| - TypeInformation<?> typeHint, |
584 |
| - RedisData sink) { |
| 590 | + TypeInformation<?> typeHint, RedisData sink) { |
585 | 591 |
|
586 | 592 | if (value == null) {
|
587 | 593 | return;
|
@@ -656,16 +662,14 @@ private void writeInternal(@Nullable String keyspace, String path, @Nullable Obj
|
656 | 662 | }
|
657 | 663 | }
|
658 | 664 |
|
659 |
| - } else if (persistentProperty.isEntity()) { |
| 665 | + } else if (propertyValue != null) { |
660 | 666 |
|
661 |
| - if (propertyValue != null) { |
662 |
| - writeInternal(keyspace, propertyStringPath, propertyValue, |
663 |
| - persistentProperty.getTypeInformation().getRequiredActualType(), sink); |
664 |
| - } |
665 |
| - } else { |
| 667 | + if (customConversions.isSimpleType(ProxyUtils.getUserClass(propertyValue.getClass()))) { |
666 | 668 |
|
667 |
| - if (propertyValue != null) { |
668 | 669 | writeToBucket(propertyStringPath, propertyValue, sink, persistentProperty.getType());
|
| 670 | + } else { |
| 671 | + writeInternal(keyspace, propertyStringPath, propertyValue, |
| 672 | + persistentProperty.getTypeInformation().getRequiredActualType(), sink); |
669 | 673 | }
|
670 | 674 | }
|
671 | 675 | });
|
|
0 commit comments