Fluent registration API for PropertyValueConverters.

Introduce a builder API to register PropertyValueConverters using simple (Bi)Functions. Additional methods on ValueConversionContext to enable advanced use cases in converter implementation. Tweak generics of VCC to be able to expose store-specific PersistentProperty implementations via the context.

See #1484
Original pull request: #2566.
This commit is contained in:
Oliver Drotbohm
2022-02-16 15:40:12 +01:00
committed by Mark Paluch
parent caf49ad739
commit e7292279bf
12 changed files with 345 additions and 59 deletions

View File

@@ -427,9 +427,12 @@ public interface PersistentProperty<P extends PersistentProperty<P>> {
}
@Nullable
default Class<? extends PropertyValueConverter<?,?, ? extends ValueConversionContext>> getValueConverterType() {
default Class<? extends PropertyValueConverter<?, ?, ? extends ValueConversionContext<?>>> getValueConverterType() {
PropertyConverter annotation = findAnnotation(PropertyConverter.class);
return annotation == null ? null : annotation.value();
return annotation == null ? null
: (Class<? extends PropertyValueConverter<?, ?, ? extends ValueConversionContext<?>>>) annotation.value();
}
default boolean hasValueConverter() {

View File

@@ -287,10 +287,12 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
@Nullable
@Override
public Class<? extends PropertyValueConverter<?, ?, ? extends ValueConversionContext>> getValueConverterType() {
@SuppressWarnings("unchecked")
public Class<? extends PropertyValueConverter<?, ?, ? extends ValueConversionContext<?>>> getValueConverterType() {
return doFindAnnotation(PropertyConverter.class) //
.map(PropertyConverter::value) //
.map(Class.class::cast) //
.orElse(null);
}