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 ;
@@ -98,6 +99,8 @@ public class CustomConversions {
98
99
private final Function <ConvertiblePair , Class <?>> getRawWriteTarget = convertiblePair -> getCustomTarget (
99
100
convertiblePair .getSourceType (), null , writingPairs );
100
101
102
+ private PropertyValueConversions propertyValueConversions ;
103
+
101
104
/**
102
105
* @param converterConfiguration the {@link ConverterConfiguration} to apply.
103
106
* @since 2.3
@@ -120,6 +123,7 @@ public CustomConversions(ConverterConfiguration converterConfiguration) {
120
123
this .converters = Collections .unmodifiableList (registeredConverters );
121
124
this .simpleTypeHolder = new SimpleTypeHolder (customSimpleTypes ,
122
125
converterConfiguration .getStoreConversions ().getStoreTypeHolder ());
126
+ this .propertyValueConversions = converterConfiguration .getPropertyValueConversions ();
123
127
}
124
128
125
129
/**
@@ -172,6 +176,36 @@ public void registerConvertersIn(ConverterRegistry conversionService) {
172
176
VavrCollectionConverters .getConvertersToRegister ().forEach (it -> registerConverterIn (it , conversionService ));
173
177
}
174
178
179
+ /**
180
+ * Delegate check if a {@link PropertyValueConverter} for the given {@literal property} is present via
181
+ * {@link PropertyValueConversions}.
182
+ *
183
+ * @param property must not be {@literal null}.
184
+ * @return {@literal true} if a specific {@link PropertyValueConverter} is available.
185
+ * @see PropertyValueConversions#hasValueConverter(PersistentProperty)
186
+ * @since ?
187
+ */
188
+ public boolean hasPropertyValueConverter (PersistentProperty <?> property ) {
189
+ return propertyValueConversions != null ? propertyValueConversions .hasValueConverter (property ) : false ;
190
+ }
191
+
192
+ /**
193
+ * Delegate to obtain the {@link PropertyValueConverter} for the given {@literal property} from
194
+ * {@link PropertyValueConversions}.
195
+ *
196
+ * @param property must not be {@literal null}. param <A> domain specific type
197
+ * @param <B> store native type
198
+ * @param <C> conversion context type
199
+ * @return the suitable {@link PropertyValueConverter} or {@literal null} if none available.
200
+ * @see PropertyValueConversions#getValueConverter(PersistentProperty)
201
+ * @since ?
202
+ */
203
+ @ Nullable
204
+ public <A , B , C extends PropertyValueConverter .ValueConversionContext > PropertyValueConverter <A , B , C > getPropertyValueConverter (
205
+ PersistentProperty <?> property ) {
206
+ return propertyValueConversions != null ? propertyValueConversions .getValueConverter (property ) : null ;
207
+ }
208
+
175
209
/**
176
210
* Get all converters and add origin information
177
211
*
@@ -877,6 +911,7 @@ protected static class ConverterConfiguration {
877
911
private final StoreConversions storeConversions ;
878
912
private final List <?> userConverters ;
879
913
private final Predicate <ConvertiblePair > converterRegistrationFilter ;
914
+ private final PropertyValueConversions propertyValueConversions ;
880
915
881
916
/**
882
917
* Create a new ConverterConfiguration holding the given {@link StoreConversions} and user defined converters.
@@ -902,9 +937,16 @@ public ConverterConfiguration(StoreConversions storeConversions, List<?> userCon
902
937
public ConverterConfiguration (StoreConversions storeConversions , List <?> userConverters ,
903
938
Predicate <ConvertiblePair > converterRegistrationFilter ) {
904
939
940
+ this (storeConversions , userConverters , converterRegistrationFilter , new SimplePropertyValueConversions ());
941
+ }
942
+
943
+ public ConverterConfiguration (StoreConversions storeConversions , List <?> userConverters ,
944
+ Predicate <ConvertiblePair > converterRegistrationFilter , @ Nullable PropertyValueConversions propertyValueConversions ) {
945
+
905
946
this .storeConversions = storeConversions ;
906
947
this .userConverters = new ArrayList <>(userConverters );
907
948
this .converterRegistrationFilter = converterRegistrationFilter ;
949
+ this .propertyValueConversions = propertyValueConversions ;
908
950
}
909
951
910
952
/**
@@ -927,5 +969,14 @@ List<?> getUserConverters() {
927
969
boolean shouldRegister (ConvertiblePair candidate ) {
928
970
return this .converterRegistrationFilter .test (candidate );
929
971
}
972
+
973
+ /**
974
+ * @return the configured {@link PropertyValueConversions} if set, {@literal null} otherwise.
975
+ * @since ?
976
+ */
977
+ @ Nullable
978
+ public PropertyValueConversions getPropertyValueConversions () {
979
+ return this .propertyValueConversions ;
980
+ }
930
981
}
931
982
}
0 commit comments