PropertyMapper

Utility that can be used to map values from a supplied source to a destination. Primarily intended to be help when mapping from @ConfigurationProperties to third-party classes.

Can filter values based on predicates and adapt values if needed. For example:

PropertyMapper map = PropertyMapper.get();
map.from(source::getName)
  .to(destination::setName);
map.from(source::getTimeout)
  .whenNonNull()
  .asInt(Duration::getSeconds)
  .to(destination::setTimeoutSecs);
map.from(source::isEnabled)
  .whenFalse().
  .toCall(destination::disable);

Mappings can ultimately be applied to a setter, trigger a method call or create a new instance.

Author

Phillip Webb

Artsiom Yudovin

Chris Bono

Since

2.0.0

Types

Link copied to clipboard
class Source<T>
A source that is in the process of being mapped.
Link copied to clipboard
An operation that can be applied to a Source.

Functions

Link copied to clipboard
Return a new PropertyMapper instance that applies the given SourceOperator to every source.
Link copied to clipboard
Return a new PropertyMapper instance that applies whenNonNull to every source.
Link copied to clipboard
open fun <T> from(value: T): PropertyMapper.Source<T>
Return a new Source from the specified value that can be used to perform the mapping.
open fun <T> from(supplier: Supplier<T>): PropertyMapper.Source<T>
Return a new Source from the specified value supplier that can be used to perform the mapping.
Link copied to clipboard
open fun get(): PropertyMapper
Return the property mapper.