Skip to content

Commit 7ab2428

Browse files
christophstroblmp911de
authored andcommitted
Make sure to initialize PropvertyValueConversions in Converter setup.
Closes #4014 Original pull request: #4015.
1 parent 350acf6 commit 7ab2428

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ public static class MongoConverterConfigurationAdapter {
156156
private boolean useNativeDriverJavaTimeCodecs = false;
157157
private final List<Object> customConverters = new ArrayList<>();
158158

159-
private PropertyValueConversions propertyValueConversions = new SimplePropertyValueConversions();
159+
private PropertyValueConversions propertyValueConversions = PropertyValueConversions.simple(it -> {});
160+
private PropertyValueConversions internallyCreatedValueConversion = propertyValueConversions;
160161

161162
/**
162163
* Create a {@link MongoConverterConfigurationAdapter} using the provided {@code converters} and our own codecs for
@@ -317,14 +318,18 @@ public MongoConverterConfigurationAdapter setPropertyValueConversions(PropertyVa
317318
PropertyValueConversions valueConversions() {
318319

319320
if (this.propertyValueConversions == null) {
320-
this.propertyValueConversions = new SimplePropertyValueConversions();
321+
this.propertyValueConversions = PropertyValueConversions.simple(it -> {});
321322
}
322323

323324
return this.propertyValueConversions;
324325
}
325326

326327
ConverterConfiguration createConverterConfiguration() {
327328

329+
if(isLocallyCreatedPropertyValueConversion() && propertyValueConversions instanceof SimplePropertyValueConversions svc) {
330+
svc.init();
331+
}
332+
328333
if (!useNativeDriverJavaTimeCodecs) {
329334
return new ConverterConfiguration(STORE_CONVERSIONS, this.customConverters, convertiblePair -> true,
330335
this.propertyValueConversions);
@@ -381,5 +386,9 @@ public LocalDate convert(Date source) {
381386
return DateToUtcLocalDateTimeConverter.INSTANCE.convert(source).toLocalDate();
382387
}
383388
}
389+
390+
private boolean isLocallyCreatedPropertyValueConversion() {
391+
return propertyValueConversions == internallyCreatedValueConversion;
392+
}
384393
}
385394
}

0 commit comments

Comments
 (0)