- All Superinterfaces:
@Incubating public interface AlternativeBinder extends TypeBinderThe binder that sets up
Alternative field bridges solve the problem of mapping one property to multiple fields depending on the value of another property.
One use case is when an entity has text properties whose content is in a different language depending on the value of another property, say
language. In that case, you probably want to analyze the text differently depending on the language. This binder solves the problem this way:
- at bootstrap, declare one index field per language (
title_fr, etc.), assigning a different analyzer to each field;
- at runtime, put the content of the text property in a different field based on the language.
In order to use this binder, you will need to:
- annotate a property with
- implement an
AlternativeBinderDelegatethat will declare the index fields (e.g. one field per language) and create an
AlternativeValueBridge. This bridge is responsible for passing the property value to the relevant field at runtime
- apply the
AlternativeBinderto the type hosting the properties (e.g. the type declaring the
languageproperty and the multi-language text properties). Generally you will want to create your own annotation for that.
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description
create(Class<D> discriminatorType, String fieldValueSourcePropertyName, Class<P> fieldValueSourcePropertyType, BeanReference<? extends AlternativeBinderDelegate<D,P>> delegateRef)
AlternativeBinder alternativeId(String id)
id- The identifier of the alternative. This is used to differentiate between multiple alternative discriminators:
assign an id when building each discriminator marker, then select the same id here.
this, for method chaining.
static <D,P> AlternativeBinder create(Class<D> discriminatorType, String fieldValueSourcePropertyName, Class<P> fieldValueSourcePropertyType, BeanReference<? extends AlternativeBinderDelegate<D,P>> delegateRef)
- Type Parameters:
D- The expected type of alternative discriminator values.
P- The expected type of the field value source.
discriminatorType- The expected type of alternative discriminator values. The alternative discriminator is designated through the
fieldValueSourcePropertyName- The expected type of the field value source, i.e. the property bound to a different field based on the discriminator.
fieldValueSourcePropertyType- The expected type of the field value source.
delegateRef- A reference to the
AlternativeBinderDelegate, responsible for binding one field per alternative and creating an