3333import org .springframework .core .convert .converter .GenericConverter .ConvertiblePair ;
3434import org .springframework .core .convert .support .GenericConversionService ;
3535import org .springframework .data .convert .ConverterBuilder .ConverterAware ;
36+ import org .springframework .data .mapping .PersistentProperty ;
3637import org .springframework .data .mapping .model .SimpleTypeHolder ;
3738import org .springframework .data .util .Predicates ;
3839import org .springframework .data .util .Streamable ;
@@ -96,6 +97,8 @@ public class CustomConversions {
9697 private final Function <ConvertiblePair , Class <?>> getRawWriteTarget = convertiblePair -> getCustomTarget (
9798 convertiblePair .getSourceType (), null , writingPairs );
9899
100+ private PropertyValueConversions propertyValueConversions ;
101+
99102 /**
100103 * @param converterConfiguration the {@link ConverterConfiguration} to apply.
101104 * @since 2.3
@@ -118,6 +121,7 @@ public CustomConversions(ConverterConfiguration converterConfiguration) {
118121 this .converters = Collections .unmodifiableList (registeredConverters );
119122 this .simpleTypeHolder = new SimpleTypeHolder (customSimpleTypes ,
120123 converterConfiguration .getStoreConversions ().getStoreTypeHolder ());
124+ this .propertyValueConversions = converterConfiguration .getPropertyValueConversions ();
121125 }
122126
123127 /**
@@ -170,6 +174,36 @@ public void registerConvertersIn(ConverterRegistry conversionService) {
170174 VavrCollectionConverters .getConvertersToRegister ().forEach (it -> registerConverterIn (it , conversionService ));
171175 }
172176
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+
173207 /**
174208 * Get all converters and add origin information
175209 *
@@ -862,6 +896,7 @@ protected static class ConverterConfiguration {
862896 private final StoreConversions storeConversions ;
863897 private final List <?> userConverters ;
864898 private final Predicate <ConvertiblePair > converterRegistrationFilter ;
899+ private final PropertyValueConversions propertyValueConversions ;
865900
866901 /**
867902 * Create a new ConverterConfiguration holding the given {@link StoreConversions} and user defined converters.
@@ -887,9 +922,16 @@ public ConverterConfiguration(StoreConversions storeConversions, List<?> userCon
887922 public ConverterConfiguration (StoreConversions storeConversions , List <?> userConverters ,
888923 Predicate <ConvertiblePair > converterRegistrationFilter ) {
889924
925+ this (storeConversions , userConverters , converterRegistrationFilter , new SimplePropertyValueConversions ());
926+ }
927+
928+ public ConverterConfiguration (StoreConversions storeConversions , List <?> userConverters ,
929+ Predicate <ConvertiblePair > converterRegistrationFilter , @ Nullable PropertyValueConversions propertyValueConversions ) {
930+
890931 this .storeConversions = storeConversions ;
891932 this .userConverters = new ArrayList <>(userConverters );
892933 this .converterRegistrationFilter = converterRegistrationFilter ;
934+ this .propertyValueConversions = propertyValueConversions ;
893935 }
894936
895937 /**
@@ -912,5 +954,14 @@ List<?> getUserConverters() {
912954 boolean shouldRegister (ConvertiblePair candidate ) {
913955 return this .converterRegistrationFilter .test (candidate );
914956 }
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+ }
915966 }
916967}
0 commit comments