|
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; |
@@ -262,12 +263,20 @@ private <R> R doReadInternal(String path, Class<R> type, RedisData source) { |
262 | 263 | protected Object readProperty(String path, RedisData source, RedisPersistentProperty persistentProperty) { |
263 | 264 |
|
264 | 265 | String currentPath = !path.isEmpty() ? path + "." + persistentProperty.getName() : persistentProperty.getName(); |
| 266 | + TypeInformation<?> typeInformation = typeMapper.readType(source.getBucket().getPropertyPath(currentPath), |
| 267 | + persistentProperty.getTypeInformation()); |
265 | 268 |
|
266 | | - TypeInformation<?> typeInformation = persistentProperty.getTypeInformation(); |
| 269 | + if (typeInformation.isMap()) { |
267 | 270 |
|
268 | | - if (persistentProperty.isMap()) { |
| 271 | + Class<?> mapValueType = null; |
269 | 272 |
|
270 | | - Class<?> mapValueType = persistentProperty.getMapValueType(); |
| 273 | + if (typeInformation.getMapValueType() != null) { |
| 274 | + mapValueType = typeInformation.getMapValueType().getType(); |
| 275 | + } |
| 276 | + |
| 277 | + if (mapValueType == null && persistentProperty.isMap()) { |
| 278 | + mapValueType = persistentProperty.getMapValueType(); |
| 279 | + } |
271 | 280 |
|
272 | 281 | if (mapValueType == null) { |
273 | 282 | throw new IllegalArgumentException("Unable to retrieve MapValueType!"); |
@@ -297,16 +306,14 @@ protected Object readProperty(String path, RedisData source, RedisPersistentProp |
297 | 306 | } |
298 | 307 | } |
299 | 308 |
|
300 | | - if (persistentProperty.isEntity() |
| 309 | + if (mappingContext.getPersistentEntity(typeInformation) != null |
301 | 310 | && !conversionService.canConvert(byte[].class, typeInformation.getRequiredActualType().getType())) { |
302 | 311 |
|
303 | 312 | Bucket bucket = source.getBucket().extract(currentPath + "."); |
304 | 313 |
|
305 | 314 | RedisData newBucket = new RedisData(bucket); |
306 | | - TypeInformation<?> typeToRead = typeMapper.readType(bucket.getPropertyPath(currentPath), |
307 | | - typeInformation); |
308 | 315 |
|
309 | | - return readInternal(currentPath, typeToRead.getType(), newBucket); |
| 316 | + return readInternal(currentPath, typeInformation.getType(), newBucket); |
310 | 317 | } |
311 | 318 |
|
312 | 319 | byte[] sourceBytes = source.getBucket().get(currentPath); |
@@ -588,8 +595,7 @@ RedisPersistentProperty getTargetPropertyOrNullForPath(String path, Class<?> typ |
588 | 595 | * @param sink |
589 | 596 | */ |
590 | 597 | private void writeInternal(@Nullable String keyspace, String path, @Nullable Object value, |
591 | | - TypeInformation<?> typeHint, |
592 | | - RedisData sink) { |
| 598 | + TypeInformation<?> typeHint, RedisData sink) { |
593 | 599 |
|
594 | 600 | if (value == null) { |
595 | 601 | return; |
@@ -664,16 +670,14 @@ private void writeInternal(@Nullable String keyspace, String path, @Nullable Obj |
664 | 670 | } |
665 | 671 | } |
666 | 672 |
|
667 | | - } else if (persistentProperty.isEntity()) { |
| 673 | + } else if (propertyValue != null) { |
668 | 674 |
|
669 | | - if (propertyValue != null) { |
670 | | - writeInternal(keyspace, propertyStringPath, propertyValue, |
671 | | - persistentProperty.getTypeInformation().getRequiredActualType(), sink); |
672 | | - } |
673 | | - } else { |
| 675 | + if (customConversions.isSimpleType(ProxyUtils.getUserClass(propertyValue.getClass()))) { |
674 | 676 |
|
675 | | - if (propertyValue != null) { |
676 | 677 | writeToBucket(propertyStringPath, propertyValue, sink, persistentProperty.getType()); |
| 678 | + } else { |
| 679 | + writeInternal(keyspace, propertyStringPath, propertyValue, |
| 680 | + persistentProperty.getTypeInformation().getRequiredActualType(), sink); |
677 | 681 | } |
678 | 682 | } |
679 | 683 | }); |
|
0 commit comments