@@ -331,7 +331,7 @@ private <R> R doReadProjection(ConversionContext context, Bson bson, EntityProje
331
331
PersistentPropertyAccessor <?> convertingAccessor = PropertyTranslatingPropertyAccessor
332
332
.create (new ConvertingPropertyAccessor <>(accessor , conversionService ), propertyTranslator );
333
333
MongoDbPropertyValueProvider valueProvider = new MongoDbPropertyValueProvider (context , documentAccessor ,
334
- evaluator );
334
+ evaluator , spELContext );
335
335
336
336
readProperties (context , entity , convertingAccessor , documentAccessor , valueProvider , evaluator ,
337
337
Predicates .isTrue ());
@@ -367,7 +367,7 @@ String getFieldName(MongoPersistentProperty prop) {
367
367
populateProperties (context , mappedEntity , documentAccessor , evaluator , instance );
368
368
369
369
PersistentPropertyAccessor <?> convertingAccessor = new ConvertingPropertyAccessor <>(accessor , conversionService );
370
- MongoDbPropertyValueProvider valueProvider = new MongoDbPropertyValueProvider (context , documentAccessor , evaluator );
370
+ MongoDbPropertyValueProvider valueProvider = new MongoDbPropertyValueProvider (context , documentAccessor , evaluator , spELContext );
371
371
372
372
readProperties (context , mappedEntity , convertingAccessor , documentAccessor , valueProvider , evaluator ,
373
373
Predicates .isTrue ());
@@ -529,7 +529,7 @@ private <S> S populateProperties(ConversionContext context, MongoPersistentEntit
529
529
ConversionContext contextToUse = context .withPath (currentPath );
530
530
531
531
MongoDbPropertyValueProvider valueProvider = new MongoDbPropertyValueProvider (contextToUse , documentAccessor ,
532
- evaluator );
532
+ evaluator , spELContext );
533
533
534
534
Predicate <MongoPersistentProperty > propertyFilter = isIdentifier (entity ).or (isConstructorArgument (entity )).negate ();
535
535
readProperties (contextToUse , entity , accessor , documentAccessor , valueProvider , evaluator , propertyFilter );
@@ -868,9 +868,9 @@ private void writeProperties(Bson bson, MongoPersistentEntity<?> entity, Persist
868
868
dbObjectAccessor .put (prop , null );
869
869
}
870
870
} else if (!conversions .isSimpleType (value .getClass ())) {
871
- writePropertyInternal (value , dbObjectAccessor , prop );
871
+ writePropertyInternal (value , dbObjectAccessor , prop , accessor );
872
872
} else {
873
- writeSimpleInternal (value , bson , prop );
873
+ writeSimpleInternal (value , bson , prop , accessor );
874
874
}
875
875
}
876
876
}
@@ -887,11 +887,11 @@ private void writeAssociation(Association<MongoPersistentProperty> association,
887
887
return ;
888
888
}
889
889
890
- writePropertyInternal (value , dbObjectAccessor , inverseProp );
890
+ writePropertyInternal (value , dbObjectAccessor , inverseProp , accessor );
891
891
}
892
892
893
893
@ SuppressWarnings ({ "unchecked" })
894
- protected void writePropertyInternal (@ Nullable Object obj , DocumentAccessor accessor , MongoPersistentProperty prop ) {
894
+ protected void writePropertyInternal (@ Nullable Object obj , DocumentAccessor accessor , MongoPersistentProperty prop , PersistentPropertyAccessor <?> persistentPropertyAccessor ) {
895
895
896
896
if (obj == null ) {
897
897
return ;
@@ -902,7 +902,13 @@ protected void writePropertyInternal(@Nullable Object obj, DocumentAccessor acce
902
902
903
903
if (conversions .hasValueConverter (prop )) {
904
904
accessor .put (prop , conversions .getPropertyValueConversions ().getValueConverter (prop ).write (obj ,
905
- new MongoConversionContext (prop , this )));
905
+ new MongoConversionContext (new PropertyValueProvider <MongoPersistentProperty >() {
906
+ @ Nullable
907
+ @ Override
908
+ public <T > T getPropertyValue (MongoPersistentProperty property ) {
909
+ return (T ) persistentPropertyAccessor .getProperty (property );
910
+ }
911
+ }, prop , this , spELContext )));
906
912
return ;
907
913
}
908
914
@@ -1234,12 +1240,18 @@ private void writeSimpleInternal(@Nullable Object value, Bson bson, String key)
1234
1240
BsonUtils .addToMap (bson , key , getPotentiallyConvertedSimpleWrite (value , Object .class ));
1235
1241
}
1236
1242
1237
- private void writeSimpleInternal (@ Nullable Object value , Bson bson , MongoPersistentProperty property ) {
1243
+ private void writeSimpleInternal (@ Nullable Object value , Bson bson , MongoPersistentProperty property , PersistentPropertyAccessor <?> persistentPropertyAccessor ) {
1238
1244
DocumentAccessor accessor = new DocumentAccessor (bson );
1239
1245
1240
1246
if (conversions .hasValueConverter (property )) {
1241
1247
accessor .put (property , conversions .getPropertyValueConversions ().getValueConverter (property ).write (value ,
1242
- new MongoConversionContext (property , this )));
1248
+ new MongoConversionContext (new PropertyValueProvider <MongoPersistentProperty >() {
1249
+ @ Nullable
1250
+ @ Override
1251
+ public <T > T getPropertyValue (MongoPersistentProperty property ) {
1252
+ return (T ) persistentPropertyAccessor .getProperty (property );
1253
+ }
1254
+ }, property , this , spELContext )));
1243
1255
return ;
1244
1256
}
1245
1257
@@ -1845,6 +1857,7 @@ static class MongoDbPropertyValueProvider implements PropertyValueProvider<Mongo
1845
1857
final ConversionContext context ;
1846
1858
final DocumentAccessor accessor ;
1847
1859
final SpELExpressionEvaluator evaluator ;
1860
+ final SpELContext spELContext ;
1848
1861
1849
1862
/**
1850
1863
* Creates a new {@link MongoDbPropertyValueProvider} for the given source, {@link SpELExpressionEvaluator} and
@@ -1855,7 +1868,7 @@ static class MongoDbPropertyValueProvider implements PropertyValueProvider<Mongo
1855
1868
* @param evaluator must not be {@literal null}.
1856
1869
*/
1857
1870
MongoDbPropertyValueProvider (ConversionContext context , Bson source , SpELExpressionEvaluator evaluator ) {
1858
- this (context , new DocumentAccessor (source ), evaluator );
1871
+ this (context , new DocumentAccessor (source ), evaluator , null );
1859
1872
}
1860
1873
1861
1874
/**
@@ -1867,7 +1880,7 @@ static class MongoDbPropertyValueProvider implements PropertyValueProvider<Mongo
1867
1880
* @param evaluator must not be {@literal null}.
1868
1881
*/
1869
1882
MongoDbPropertyValueProvider (ConversionContext context , DocumentAccessor accessor ,
1870
- SpELExpressionEvaluator evaluator ) {
1883
+ SpELExpressionEvaluator evaluator , SpELContext spELContext ) {
1871
1884
1872
1885
Assert .notNull (context , "ConversionContext must no be null" );
1873
1886
Assert .notNull (accessor , "DocumentAccessor must no be null" );
@@ -1876,6 +1889,7 @@ static class MongoDbPropertyValueProvider implements PropertyValueProvider<Mongo
1876
1889
this .context = context ;
1877
1890
this .accessor = accessor ;
1878
1891
this .evaluator = evaluator ;
1892
+ this .spELContext = spELContext ;
1879
1893
}
1880
1894
1881
1895
@ Nullable
@@ -1892,7 +1906,7 @@ public <T> T getPropertyValue(MongoPersistentProperty property) {
1892
1906
CustomConversions conversions = context .getCustomConversions ();
1893
1907
if (conversions .hasValueConverter (property )) {
1894
1908
return (T ) conversions .getPropertyValueConversions ().getValueConverter (property ).read (value ,
1895
- new MongoConversionContext (property , context .getSourceConverter ()));
1909
+ new MongoConversionContext (this , property , context .getSourceConverter (), spELContext ));
1896
1910
}
1897
1911
1898
1912
ConversionContext contextToUse = context .forProperty (property );
@@ -1902,7 +1916,7 @@ public <T> T getPropertyValue(MongoPersistentProperty property) {
1902
1916
1903
1917
public MongoDbPropertyValueProvider withContext (ConversionContext context ) {
1904
1918
1905
- return context == this .context ? this : new MongoDbPropertyValueProvider (context , accessor , evaluator );
1919
+ return context == this .context ? this : new MongoDbPropertyValueProvider (context , accessor , evaluator , spELContext );
1906
1920
}
1907
1921
}
1908
1922
@@ -1925,7 +1939,7 @@ class AssociationAwareMongoDbPropertyValueProvider extends MongoDbPropertyValueP
1925
1939
*/
1926
1940
AssociationAwareMongoDbPropertyValueProvider (ConversionContext context , DocumentAccessor source ,
1927
1941
SpELExpressionEvaluator evaluator ) {
1928
- super (context , source , evaluator );
1942
+ super (context , source , evaluator , MappingMongoConverter . this . spELContext );
1929
1943
}
1930
1944
1931
1945
@ Override
0 commit comments