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 ;
@@ -98,6 +99,8 @@ public class CustomConversions {
9899 private final Function <ConvertiblePair , Class <?>> getRawWriteTarget = convertiblePair -> getCustomTarget (
99100 convertiblePair .getSourceType (), null , writingPairs );
100101
102+ private PropertyValueConversions propertyValueConversions ;
103+
101104 /**
102105 * @param converterConfiguration the {@link ConverterConfiguration} to apply.
103106 * @since 2.3
@@ -120,6 +123,7 @@ public CustomConversions(ConverterConfiguration converterConfiguration) {
120123 this .converters = Collections .unmodifiableList (registeredConverters );
121124 this .simpleTypeHolder = new SimpleTypeHolder (customSimpleTypes ,
122125 converterConfiguration .getStoreConversions ().getStoreTypeHolder ());
126+ this .propertyValueConversions = converterConfiguration .getPropertyValueConversions ();
123127 }
124128
125129 /**
@@ -172,6 +176,36 @@ public void registerConvertersIn(ConverterRegistry conversionService) {
172176 VavrCollectionConverters .getConvertersToRegister ().forEach (it -> registerConverterIn (it , conversionService ));
173177 }
174178
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+
175209 /**
176210 * Get all converters and add origin information
177211 *
@@ -877,6 +911,7 @@ protected static class ConverterConfiguration {
877911 private final StoreConversions storeConversions ;
878912 private final List <?> userConverters ;
879913 private final Predicate <ConvertiblePair > converterRegistrationFilter ;
914+ private final PropertyValueConversions propertyValueConversions ;
880915
881916 /**
882917 * Create a new ConverterConfiguration holding the given {@link StoreConversions} and user defined converters.
@@ -902,9 +937,16 @@ public ConverterConfiguration(StoreConversions storeConversions, List<?> userCon
902937 public ConverterConfiguration (StoreConversions storeConversions , List <?> userConverters ,
903938 Predicate <ConvertiblePair > converterRegistrationFilter ) {
904939
940+ this (storeConversions , userConverters , converterRegistrationFilter , new SimplePropertyValueConversions ());
941+ }
942+
943+ public ConverterConfiguration (StoreConversions storeConversions , List <?> userConverters ,
944+ Predicate <ConvertiblePair > converterRegistrationFilter , @ Nullable PropertyValueConversions propertyValueConversions ) {
945+
905946 this .storeConversions = storeConversions ;
906947 this .userConverters = new ArrayList <>(userConverters );
907948 this .converterRegistrationFilter = converterRegistrationFilter ;
949+ this .propertyValueConversions = propertyValueConversions ;
908950 }
909951
910952 /**
@@ -927,5 +969,14 @@ List<?> getUserConverters() {
927969 boolean shouldRegister (ConvertiblePair candidate ) {
928970 return this .converterRegistrationFilter .test (candidate );
929971 }
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+ }
930981 }
931982}
0 commit comments