BindHandler class

Hooks into a Binder.bind call, called for every property bound on the way: the top-level name, then each nested property and element.

Use one to watch or adjust binding: log which properties were used, skip some names, replace values, or decide that a value which cannot be converted is not an error (@ConfigurationProperties(ignoreInvalidFields: true) works this way). Extend it and override what you need; the defaults change nothing. Most code never needs one.

final class LoggingBindHandler extends BindHandler {
  const LoggingBindHandler();

  @override
  Object? onSuccess(
    ConfigurationPropertyName name,
    TypeInfo<Object?> target,
    Object? result,
  ) {
    log.info('bound $name');
    return result;
  }
}

binder.bind('app', appType, handler: const LoggingBindHandler());

Spring (Java): binder.bind("app", Bindable.of(App.class), handler). One difference: onFailure gets the error message and decides whether it counts, where Spring Boot's returns a replacement value or rethrows.

Constructors

BindHandler()
A handler that changes nothing; subclasses override some methods.
const

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onFailure(ConfigurationPropertyName name, String error) → bool
Called when name cannot be bound; error is the message that would be reported (app.port: failed to convert to int (was "x")).
onFinish(ConfigurationPropertyName name, TypeInfo<Object?> target, Object? result) → void
Called last for every name, bound or not; result is the final value, or null when nothing was bound.
onStart(ConfigurationPropertyName name, TypeInfo<Object?> target) → bool
Called before name is bound to target. Return false to skip the name: it stays unbound, as if no property were set.
onSuccess(ConfigurationPropertyName name, TypeInfo<Object?> target, Object? result) → Object?
Called after name was bound to result. Returns the value to use instead, which is result by default.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Constants

defaultHandler → const BindHandler
The handler Binder.bind uses when none is given: it binds as is and reports every failure.