33
33
import org .springframework .core .convert .converter .GenericConverter .ConvertiblePair ;
34
34
import org .springframework .core .convert .support .GenericConversionService ;
35
35
import org .springframework .data .convert .ConverterBuilder .ConverterAware ;
36
+ import org .springframework .data .mapping .PersistentProperty ;
36
37
import org .springframework .data .mapping .model .SimpleTypeHolder ;
37
38
import org .springframework .data .util .Predicates ;
38
39
import org .springframework .data .util .Streamable ;
@@ -96,6 +97,8 @@ public class CustomConversions {
96
97
private final Function <ConvertiblePair , Class <?>> getRawWriteTarget = convertiblePair -> getCustomTarget (
97
98
convertiblePair .getSourceType (), null , writingPairs );
98
99
100
+ private PropertyValueConversions propertyValueConversions ;
101
+
99
102
/**
100
103
* @param converterConfiguration the {@link ConverterConfiguration} to apply.
101
104
* @since 2.3
@@ -118,6 +121,7 @@ public CustomConversions(ConverterConfiguration converterConfiguration) {
118
121
this .converters = Collections .unmodifiableList (registeredConverters );
119
122
this .simpleTypeHolder = new SimpleTypeHolder (customSimpleTypes ,
120
123
converterConfiguration .getStoreConversions ().getStoreTypeHolder ());
124
+ this .propertyValueConversions = converterConfiguration .getPropertyValueConversions ();
121
125
}
122
126
123
127
/**
@@ -170,6 +174,36 @@ public void registerConvertersIn(ConverterRegistry conversionService) {
170
174
VavrCollectionConverters .getConvertersToRegister ().forEach (it -> registerConverterIn (it , conversionService ));
171
175
}
172
176
177
+ /**
178
+ * Delegate check if a {@link PropertyValueConverter} for the given {@literal property} is present via
179
+ * {@link PropertyValueConversions}.
180
+ *
181
+ * @param property must not be {@literal null}.
182
+ * @return {@literal true} if a specific {@link PropertyValueConverter} is available.
183
+ * @see PropertyValueConversions#hasValueConverter(PersistentProperty)
184
+ * @since ?
185
+ */
186
+ public boolean hasPropertyValueConverter (PersistentProperty <?> property ) {
187
+ return propertyValueConversions != null ? propertyValueConversions .hasValueConverter (property ) : false ;
188
+ }
189
+
190
+ /**
191
+ * Delegate to obtain the {@link PropertyValueConverter} for the given {@literal property} from
192
+ * {@link PropertyValueConversions}.
193
+ *
194
+ * @param property must not be {@literal null}. param <A> domain specific type
195
+ * @param <B> store native type
196
+ * @param <C> conversion context type
197
+ * @return the suitable {@link PropertyValueConverter} or {@literal null} if none available.
198
+ * @see PropertyValueConversions#getValueConverter(PersistentProperty)
199
+ * @since ?
200
+ */
201
+ @ Nullable
202
+ public <A , B , C extends PropertyValueConverter .ValueConversionContext > PropertyValueConverter <A , B , C > getPropertyValueConverter (
203
+ PersistentProperty <?> property ) {
204
+ return propertyValueConversions != null ? propertyValueConversions .getValueConverter (property ) : null ;
205
+ }
206
+
173
207
/**
174
208
* Get all converters and add origin information
175
209
*
@@ -862,6 +896,7 @@ protected static class ConverterConfiguration {
862
896
private final StoreConversions storeConversions ;
863
897
private final List <?> userConverters ;
864
898
private final Predicate <ConvertiblePair > converterRegistrationFilter ;
899
+ private final PropertyValueConversions propertyValueConversions ;
865
900
866
901
/**
867
902
* Create a new ConverterConfiguration holding the given {@link StoreConversions} and user defined converters.
@@ -887,9 +922,16 @@ public ConverterConfiguration(StoreConversions storeConversions, List<?> userCon
887
922
public ConverterConfiguration (StoreConversions storeConversions , List <?> userConverters ,
888
923
Predicate <ConvertiblePair > converterRegistrationFilter ) {
889
924
925
+ this (storeConversions , userConverters , converterRegistrationFilter , new SimplePropertyValueConversions ());
926
+ }
927
+
928
+ public ConverterConfiguration (StoreConversions storeConversions , List <?> userConverters ,
929
+ Predicate <ConvertiblePair > converterRegistrationFilter , @ Nullable PropertyValueConversions propertyValueConversions ) {
930
+
890
931
this .storeConversions = storeConversions ;
891
932
this .userConverters = new ArrayList <>(userConverters );
892
933
this .converterRegistrationFilter = converterRegistrationFilter ;
934
+ this .propertyValueConversions = propertyValueConversions ;
893
935
}
894
936
895
937
/**
@@ -912,5 +954,14 @@ List<?> getUserConverters() {
912
954
boolean shouldRegister (ConvertiblePair candidate ) {
913
955
return this .converterRegistrationFilter .test (candidate );
914
956
}
957
+
958
+ /**
959
+ * @return the configured {@link PropertyValueConversions} if set, {@literal null} otherwise.
960
+ * @since ?
961
+ */
962
+ @ Nullable
963
+ public PropertyValueConversions getPropertyValueConversions () {
964
+ return this .propertyValueConversions ;
965
+ }
915
966
}
916
967
}
0 commit comments