Skip to content

Commit 705f1b4

Browse files
christophstroblmp911de
authored andcommitted
Make sure to initialize PropvertyValueConversions in Converter setup.
Closes #4014 Original pull request: #4015.
1 parent 198fcbb commit 705f1b4

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MongoCustomConversions.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ public static class MongoConverterConfigurationAdapter {
166166
private boolean useNativeDriverJavaTimeCodecs = false;
167167
private final List<Object> customConverters = new ArrayList<>();
168168

169-
private PropertyValueConversions propertyValueConversions = new SimplePropertyValueConversions();
169+
private PropertyValueConversions propertyValueConversions = PropertyValueConversions.simple(it -> {});
170+
private PropertyValueConversions internallyCreatedValueConversion = propertyValueConversions;
170171

171172
/**
172173
* Create a {@link MongoConverterConfigurationAdapter} using the provided {@code converters} and our own codecs for
@@ -327,14 +328,18 @@ public MongoConverterConfigurationAdapter setPropertyValueConversions(PropertyVa
327328
PropertyValueConversions valueConversions() {
328329

329330
if (this.propertyValueConversions == null) {
330-
this.propertyValueConversions = new SimplePropertyValueConversions();
331+
this.propertyValueConversions = PropertyValueConversions.simple(it -> {});
331332
}
332333

333334
return this.propertyValueConversions;
334335
}
335336

336337
ConverterConfiguration createConverterConfiguration() {
337338

339+
if(isLocallyCreatedPropertyValueConversion() && propertyValueConversions instanceof SimplePropertyValueConversions svc) {
340+
svc.init();
341+
}
342+
338343
if (!useNativeDriverJavaTimeCodecs) {
339344
return new ConverterConfiguration(STORE_CONVERSIONS, this.customConverters, convertiblePair -> true,
340345
this.propertyValueConversions);
@@ -391,5 +396,9 @@ public LocalDate convert(Date source) {
391396
return DateToUtcLocalDateTimeConverter.INSTANCE.convert(source).toLocalDate();
392397
}
393398
}
399+
400+
private boolean isLocallyCreatedPropertyValueConversion() {
401+
return propertyValueConversions == internallyCreatedValueConversion;
402+
}
394403
}
395404
}

0 commit comments

Comments
 (0)