Class PropertyMapper
java.lang.Object
org.springframework.boot.context.properties.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.
- Since:
- 2.0.0
- Author:
- Phillip Webb, Artsiom Yudovin, Chris Bono
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA source that is in the process of being mapped.static interfaceAn operation that can be applied to aPropertyMapper.Source. -
Method Summary
Modifier and TypeMethodDescriptionalwaysApplying(PropertyMapper.SourceOperator operator) Return a newPropertyMapperinstance that applies the givenPropertyMapper.SourceOperatorto every source.Return a newPropertyMapperinstance that applieswhenNonNullto every source.<T> PropertyMapper.Source<T>Return a newPropertyMapper.Sourcefrom the specified value supplier that can be used to perform the mapping.<T> PropertyMapper.Source<T>from(T value) Return a newPropertyMapper.Sourcefrom the specified value that can be used to perform the mapping.static PropertyMapperget()Return the property mapper.
-
Method Details
-
alwaysApplyingWhenNonNull
Return a newPropertyMapperinstance that applieswhenNonNullto every source.- Returns:
- a new property mapper instance
-
alwaysApplying
Return a newPropertyMapperinstance that applies the givenPropertyMapper.SourceOperatorto every source.- Parameters:
operator- the source operator to apply- Returns:
- a new property mapper instance
-
from
Return a newPropertyMapper.Sourcefrom the specified value supplier that can be used to perform the mapping.- Type Parameters:
T- the source type- Parameters:
supplier- the value supplier- Returns:
- a
PropertyMapper.Sourcethat can be used to complete the mapping - See Also:
-
from
Return a newPropertyMapper.Sourcefrom the specified value that can be used to perform the mapping.- Type Parameters:
T- the source type- Parameters:
value- the value- Returns:
- a
PropertyMapper.Sourcethat can be used to complete the mapping
-
get
Return the property mapper.- Returns:
- the property mapper
-