@@ -176,7 +176,7 @@ protected ConversionContext getConversionContext(ObjectPath path) {
176
176
177
177
Assert .notNull (path , "ObjectPath must not be null" );
178
178
179
- return new ConversionContext (conversions , path , this ::readDocument , this ::readCollectionOrArray , this ::readMap ,
179
+ return new ConversionContext (this , conversions , path , this ::readDocument , this ::readCollectionOrArray , this ::readMap ,
180
180
this ::readDBRef , this ::getPotentiallyConvertedSimpleRead );
181
181
}
182
182
@@ -294,7 +294,7 @@ public <R> R project(EntityProjection<R, ?> projection, Bson bson) {
294
294
return (R ) read (typeToRead , bson );
295
295
}
296
296
297
- ProjectingConversionContext context = new ProjectingConversionContext (conversions , ObjectPath .ROOT ,
297
+ ProjectingConversionContext context = new ProjectingConversionContext (this , conversions , ObjectPath .ROOT ,
298
298
this ::readCollectionOrArray , this ::readMap , this ::readDBRef , this ::getPotentiallyConvertedSimpleRead ,
299
299
projection );
300
300
@@ -377,11 +377,11 @@ class ProjectingConversionContext extends ConversionContext {
377
377
378
378
private final EntityProjection <?, ?> returnedTypeDescriptor ;
379
379
380
- ProjectingConversionContext (CustomConversions customConversions , ObjectPath path ,
380
+ ProjectingConversionContext (MongoConverter sourceConverter , CustomConversions customConversions , ObjectPath path ,
381
381
ContainerValueConverter <Collection <?>> collectionConverter , ContainerValueConverter <Bson > mapConverter ,
382
382
ContainerValueConverter <DBRef > dbRefConverter , ValueConverter <Object > elementConverter ,
383
383
EntityProjection <?, ?> projection ) {
384
- super (customConversions , path ,
384
+ super (sourceConverter , customConversions , path ,
385
385
(context , source , typeHint ) -> doReadOrProject (context , source , typeHint , projection ),
386
386
387
387
collectionConverter , mapConverter , dbRefConverter , elementConverter );
@@ -397,13 +397,13 @@ public ConversionContext forProperty(String name) {
397
397
mapConverter , dbRefConverter , elementConverter );
398
398
}
399
399
400
- return new ProjectingConversionContext (conversions , path , collectionConverter , mapConverter , dbRefConverter ,
400
+ return new ProjectingConversionContext (sourceConverter , conversions , path , collectionConverter , mapConverter , dbRefConverter ,
401
401
elementConverter , property );
402
402
}
403
403
404
404
@ Override
405
405
public ConversionContext withPath (ObjectPath currentPath ) {
406
- return new ProjectingConversionContext (conversions , currentPath , collectionConverter , mapConverter ,
406
+ return new ProjectingConversionContext (sourceConverter , conversions , currentPath , collectionConverter , mapConverter ,
407
407
dbRefConverter , elementConverter , returnedTypeDescriptor );
408
408
}
409
409
}
@@ -935,6 +935,11 @@ protected void writePropertyInternal(@Nullable Object obj, DocumentAccessor acce
935
935
TypeInformation <?> valueType = ClassTypeInformation .from (obj .getClass ());
936
936
TypeInformation <?> type = prop .getTypeInformation ();
937
937
938
+ if (conversions .hasPropertyValueConverter (prop )) {
939
+ accessor .put (prop , conversions .getPropertyValueConverter (prop ).write (obj , new MongoConversionContext (prop , this )));
940
+ return ;
941
+ }
942
+
938
943
if (prop .isUnwrapped ()) {
939
944
940
945
Document target = new Document ();
@@ -1264,6 +1269,12 @@ private void writeSimpleInternal(@Nullable Object value, Bson bson, String key)
1264
1269
1265
1270
private void writeSimpleInternal (@ Nullable Object value , Bson bson , MongoPersistentProperty property ) {
1266
1271
DocumentAccessor accessor = new DocumentAccessor (bson );
1272
+
1273
+ if (conversions .hasPropertyValueConverter (property )) {
1274
+ accessor .put (property , conversions .getPropertyValueConverter (property ).write (value , new MongoConversionContext (property , this )));
1275
+ return ;
1276
+ }
1277
+
1267
1278
accessor .put (property , getPotentiallyConvertedSimpleWrite (value ,
1268
1279
property .hasExplicitWriteTarget () ? property .getFieldType () : Object .class ));
1269
1280
}
@@ -1905,6 +1916,11 @@ public <T> T getPropertyValue(MongoPersistentProperty property) {
1905
1916
return null ;
1906
1917
}
1907
1918
1919
+ if (context .conversions .hasPropertyValueConverter (property )) {
1920
+
1921
+ return (T ) context .conversions .getPropertyValueConverter (property ).read (value , new MongoConversionContext (property , context .sourceConverter ));
1922
+ }
1923
+
1908
1924
return (T ) context .convert (value , property .getTypeInformation ());
1909
1925
}
1910
1926
@@ -2123,6 +2139,7 @@ public org.springframework.data.util.TypeInformation<? extends S> specialize(Cla
2123
2139
*/
2124
2140
protected static class ConversionContext {
2125
2141
2142
+ final MongoConverter sourceConverter ;
2126
2143
final org .springframework .data .convert .CustomConversions conversions ;
2127
2144
final ObjectPath path ;
2128
2145
final ContainerValueConverter <Bson > documentConverter ;
@@ -2131,11 +2148,12 @@ protected static class ConversionContext {
2131
2148
final ContainerValueConverter <DBRef > dbRefConverter ;
2132
2149
final ValueConverter <Object > elementConverter ;
2133
2150
2134
- ConversionContext (org .springframework .data .convert .CustomConversions customConversions , ObjectPath path ,
2151
+ ConversionContext (MongoConverter sourceConverter , org .springframework .data .convert .CustomConversions customConversions , ObjectPath path ,
2135
2152
ContainerValueConverter <Bson > documentConverter , ContainerValueConverter <Collection <?>> collectionConverter ,
2136
2153
ContainerValueConverter <Bson > mapConverter , ContainerValueConverter <DBRef > dbRefConverter ,
2137
2154
ValueConverter <Object > elementConverter ) {
2138
2155
2156
+ this .sourceConverter = sourceConverter ;
2139
2157
this .conversions = customConversions ;
2140
2158
this .path = path ;
2141
2159
this .documentConverter = documentConverter ;
@@ -2217,7 +2235,7 @@ public ConversionContext withPath(ObjectPath currentPath) {
2217
2235
2218
2236
Assert .notNull (currentPath , "ObjectPath must not be null" );
2219
2237
2220
- return new ConversionContext (conversions , currentPath , documentConverter , collectionConverter , mapConverter ,
2238
+ return new ConversionContext (sourceConverter , conversions , currentPath , documentConverter , collectionConverter , mapConverter ,
2221
2239
dbRefConverter , elementConverter );
2222
2240
}
2223
2241
0 commit comments