Class PropertyMapper

java.lang.Object
org.springframework.boot.context.properties.PropertyMapper

public final class PropertyMapper extends Object
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)
   .when(this::thisYear)
   .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.

By default null values and any NullPointerException thrown from the supplier are filtered and will not be applied to consumers. If you want to apply nulls, you can use PropertyMapper.Source.always().

Since:
2.0.0
Author:
Phillip Webb, Artsiom Yudovin, Chris Bono, Moritz Halbritter