| Right now defining a converter is quite complicated, as illustrated by the documentation. I think we could improve on this by moving the part about casting and checking the type out of the converters. We would then just pass a class when setting a converter. For example instead of this:
f.asString()
.dslConverter( new ToDocumentFieldValueConverter<ISBN, String>() {
@Override
public boolean isValidInputType(Class<?> inputTypeCandidate) {
return ISBN.class.isAssignableFrom( inputTypeCandidate );
}
@Override
public String convert(ISBN value, ToDocumentFieldValueConvertContext context) {
return value.getStringValue();
}
@Override
public String convertUnknown(Object value, ToDocumentFieldValueConvertContext context) {
return convert( (ISBN) value, context );
}
} )
We would do this:
f.asString()
.dslConverter( ISBN.class, new ToDocumentFieldValueConverter<ISBN, String>() {
@Override
public String convert(ISBN value, ToDocumentFieldValueConvertContext context) {
return value.getStringValue();
}
} )
We could even use lambdas when isCompatibleWith doesn't need to be implemented. |