Interface BindHandler
- All Known Implementing Classes:
AbstractBindHandler
,IgnoreErrorsBindHandler
,IgnoreTopLevelConverterNotFoundBindHandler
,NoUnboundElementsBindHandler
,ValidationBindHandler
public interface BindHandler
Callback interface that can be used to handle additional logic during elementbinding
.- Since:
- 2.0.0
Field Summary
Fields Modifier and Type Field Description static BindHandler
DEFAULT
Default no-op bind handler.
Method Summary
All Methods Instance Methods Default Methods Modifier and Type Method Description default Object
onFailure(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Exception error)
Called when binding fails for any reason (including failures fromonSuccess(org.springframework.boot.context.properties.source.ConfigurationPropertyName, org.springframework.boot.context.properties.bind.Bindable<?>, org.springframework.boot.context.properties.bind.BindContext, java.lang.Object)
calls).default void
onFinish(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Object result)
Called when binding finishes, regardless of whether the property was bound or not.default <T> Bindable<T>
onStart(ConfigurationPropertyName name, Bindable<T> target, BindContext context)
Called when binding of an element starts but before any result has been determined.default Object
onSuccess(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Object result)
Called when binding of an element ends with a successful result.
Field Detail
DEFAULT
static final BindHandler DEFAULT
Default no-op bind handler.
Method Detail
onStart
default <T> Bindable<T> onStart(ConfigurationPropertyName name, Bindable<T> target, BindContext context)
Called when binding of an element starts but before any result has been determined.- Type Parameters:
T
- the bindable source type- Parameters:
name
- the name of the element being boundtarget
- the item being boundcontext
- the bind context- Returns:
- the actual item that should be used for binding (may be
null
)
onSuccess
default Object onSuccess(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Object result)
Called when binding of an element ends with a successful result. Implementations may change the ultimately returned result or perform addition validation.- Parameters:
name
- the name of the element being boundtarget
- the item being boundcontext
- the bind contextresult
- the bound result (nevernull
)- Returns:
- the actual result that should be used (may be
null
)
onFailure
default Object onFailure(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Exception error) throws Exception
Called when binding fails for any reason (including failures fromonSuccess(org.springframework.boot.context.properties.source.ConfigurationPropertyName, org.springframework.boot.context.properties.bind.Bindable<?>, org.springframework.boot.context.properties.bind.BindContext, java.lang.Object)
calls). Implementations may choose to swallow exceptions and return an alternative result.- Parameters:
name
- the name of the element being boundtarget
- the item being boundcontext
- the bind contexterror
- the cause of the error (if the exception stands it may be re-thrown)- Returns:
- the actual result that should be used (may be
null
). - Throws:
Exception
- if the binding isn't valid
onFinish
default void onFinish(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Object result) throws Exception
Called when binding finishes, regardless of whether the property was bound or not.- Parameters:
name
- the name of the element being boundtarget
- the item being boundcontext
- the bind contextresult
- the bound result (may benull
)- Throws:
Exception
- if the binding isn't valid