|
38 | 38 | import org.bson.conversions.Bson;
|
39 | 39 | import org.bson.json.JsonReader;
|
40 | 40 | import org.bson.types.ObjectId;
|
| 41 | + |
41 | 42 | import org.springframework.beans.BeansException;
|
42 | 43 | import org.springframework.beans.factory.BeanClassLoaderAware;
|
43 | 44 | import org.springframework.context.ApplicationContext;
|
@@ -415,8 +416,8 @@ public ConversionContext forProperty(String name) {
|
415 | 416 |
|
416 | 417 | EntityProjection<?, ?> property = returnedTypeDescriptor.findProperty(name);
|
417 | 418 | if (property == null) {
|
418 |
| - return new ConversionContext(sourceConverter, conversions, path, MappingMongoConverter.this::readDocument, collectionConverter, |
419 |
| - mapConverter, dbRefConverter, elementConverter); |
| 419 | + return new ConversionContext(sourceConverter, conversions, path, MappingMongoConverter.this::readDocument, |
| 420 | + collectionConverter, mapConverter, dbRefConverter, elementConverter); |
420 | 421 | }
|
421 | 422 |
|
422 | 423 | return new ProjectingConversionContext(sourceConverter, conversions, path, collectionConverter, mapConverter,
|
@@ -966,8 +967,8 @@ protected void writePropertyInternal(@Nullable Object obj, DocumentAccessor acce
|
966 | 967 | TypeInformation<?> type = prop.getTypeInformation();
|
967 | 968 |
|
968 | 969 | if (conversions.getPropertyValueConversions().hasValueConverter(prop)) {
|
969 |
| - accessor.put(prop, |
970 |
| - conversions.getPropertyValueConversions().getValueConverter(prop).write(obj, new MongoConversionContext(prop, this))); |
| 970 | + accessor.put(prop, conversions.getPropertyValueConversions().getValueConverter(prop).write(obj, |
| 971 | + new MongoConversionContext(prop, this))); |
971 | 972 | return;
|
972 | 973 | }
|
973 | 974 |
|
@@ -1302,9 +1303,8 @@ private void writeSimpleInternal(@Nullable Object value, Bson bson, MongoPersist
|
1302 | 1303 | DocumentAccessor accessor = new DocumentAccessor(bson);
|
1303 | 1304 |
|
1304 | 1305 | if (conversions.getPropertyValueConversions().hasValueConverter(property)) {
|
1305 |
| - accessor.put(property, |
1306 |
| - conversions.getPropertyValueConversions().getValueConverter(property) |
1307 |
| - .write(value, new MongoConversionContext(property, this))); |
| 1306 | + accessor.put(property, conversions.getPropertyValueConversions().getValueConverter(property).write(value, |
| 1307 | + new MongoConversionContext(property, this))); |
1308 | 1308 | return;
|
1309 | 1309 | }
|
1310 | 1310 |
|
@@ -1971,12 +1971,15 @@ public <T> T getPropertyValue(MongoPersistentProperty property) {
|
1971 | 1971 | return null;
|
1972 | 1972 | }
|
1973 | 1973 |
|
1974 |
| - if (context.conversions.getPropertyValueConversions().hasValueConverter(property)) { |
1975 |
| - return (T) context.conversions.getPropertyValueConversions().getValueConverter(property).read(value, |
| 1974 | + CustomConversions conversions = context.conversions; |
| 1975 | + if (conversions.getPropertyValueConversions().hasValueConverter(property)) { |
| 1976 | + return (T) conversions.getPropertyValueConversions().getValueConverter(property).read(value, |
1976 | 1977 | new MongoConversionContext(property, context.sourceConverter));
|
1977 | 1978 | }
|
1978 | 1979 |
|
1979 |
| - return (T) context.convert(value, property.getTypeInformation()); |
| 1980 | + ConversionContext contextToUse = context.forProperty(property.getName()); |
| 1981 | + |
| 1982 | + return (T) contextToUse.convert(value, property.getTypeInformation()); |
1980 | 1983 | }
|
1981 | 1984 |
|
1982 | 1985 | public MongoDbPropertyValueProvider withContext(ConversionContext context) {
|
|
0 commit comments