|
17 | 17 |
|
18 | 18 | import java.lang.reflect.Constructor;
|
19 | 19 | import java.lang.reflect.Method;
|
20 |
| -import java.util.*; |
| 20 | +import java.util.ArrayList; |
| 21 | +import java.util.Arrays; |
| 22 | +import java.util.Collection; |
| 23 | +import java.util.Collections; |
| 24 | +import java.util.HashSet; |
| 25 | +import java.util.LinkedHashMap; |
| 26 | +import java.util.List; |
| 27 | +import java.util.Map; |
| 28 | +import java.util.Optional; |
| 29 | +import java.util.Set; |
21 | 30 | import java.util.function.Predicate;
|
22 | 31 | import java.util.stream.Collectors;
|
23 | 32 |
|
|
30 | 39 | import org.bson.conversions.Bson;
|
31 | 40 | import org.bson.json.JsonReader;
|
32 | 41 | import org.bson.types.ObjectId;
|
| 42 | + |
33 | 43 | import org.springframework.beans.BeansException;
|
34 | 44 | import org.springframework.beans.factory.BeanClassLoaderAware;
|
35 | 45 | import org.springframework.context.ApplicationContext;
|
@@ -395,8 +405,8 @@ public ConversionContext forProperty(String name) {
|
395 | 405 |
|
396 | 406 | EntityProjection<?, ?> property = returnedTypeDescriptor.findProperty(name);
|
397 | 407 | if (property == null) {
|
398 |
| - return new ConversionContext(sourceConverter, conversions, path, MappingMongoConverter.this::readDocument, collectionConverter, |
399 |
| - mapConverter, dbRefConverter, elementConverter); |
| 408 | + return new ConversionContext(sourceConverter, conversions, path, MappingMongoConverter.this::readDocument, |
| 409 | + collectionConverter, mapConverter, dbRefConverter, elementConverter); |
400 | 410 | }
|
401 | 411 |
|
402 | 412 | return new ProjectingConversionContext(sourceConverter, conversions, path, collectionConverter, mapConverter,
|
@@ -938,9 +948,8 @@ protected void writePropertyInternal(@Nullable Object obj, DocumentAccessor acce
|
938 | 948 | TypeInformation<?> type = prop.getTypeInformation();
|
939 | 949 |
|
940 | 950 | if (conversions.hasValueConverter(prop)) {
|
941 |
| - accessor.put(prop, |
942 |
| - conversions.getPropertyValueConversions().getValueConverter(prop) |
943 |
| - .write(obj, new MongoConversionContext(prop, this))); |
| 951 | + accessor.put(prop, conversions.getPropertyValueConversions().getValueConverter(prop).write(obj, |
| 952 | + new MongoConversionContext(prop, this))); |
944 | 953 | return;
|
945 | 954 | }
|
946 | 955 |
|
@@ -1275,9 +1284,8 @@ private void writeSimpleInternal(@Nullable Object value, Bson bson, MongoPersist
|
1275 | 1284 | DocumentAccessor accessor = new DocumentAccessor(bson);
|
1276 | 1285 |
|
1277 | 1286 | if (conversions.hasValueConverter(property)) {
|
1278 |
| - accessor.put(property, |
1279 |
| - conversions.getPropertyValueConversions().getValueConverter(property) |
1280 |
| - .write(value, new MongoConversionContext(property, this))); |
| 1287 | + accessor.put(property, conversions.getPropertyValueConversions().getValueConverter(property).write(value, |
| 1288 | + new MongoConversionContext(property, this))); |
1281 | 1289 | return;
|
1282 | 1290 | }
|
1283 | 1291 |
|
@@ -1927,12 +1935,15 @@ public <T> T getPropertyValue(MongoPersistentProperty property) {
|
1927 | 1935 | return null;
|
1928 | 1936 | }
|
1929 | 1937 |
|
1930 |
| - if (context.conversions.hasValueConverter(property)) { |
1931 |
| - return (T) context.conversions.getPropertyValueConversions().getValueConverter(property).read(value, |
| 1938 | + CustomConversions conversions = context.conversions; |
| 1939 | + if (conversions.hasValueConverter(property)) { |
| 1940 | + return (T) conversions.getPropertyValueConversions().getValueConverter(property).read(value, |
1932 | 1941 | new MongoConversionContext(property, context.sourceConverter));
|
1933 | 1942 | }
|
1934 | 1943 |
|
1935 |
| - return (T) context.convert(value, property.getTypeInformation()); |
| 1944 | + ConversionContext contextToUse = context.forProperty(property.getName()); |
| 1945 | + |
| 1946 | + return (T) contextToUse.convert(value, property.getTypeInformation()); |
1936 | 1947 | }
|
1937 | 1948 |
|
1938 | 1949 | public MongoDbPropertyValueProvider withContext(ConversionContext context) {
|
|
0 commit comments