类 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) .whenNonNull() .asInt(Duration::getSeconds) .to(destination::setTimeoutSecs); map.from(source::isEnabled) .whenFalse(). .toCall(destination::disable);
Mappings can ultimately be applied to a
setter
, trigger amethod call
or create anew instance
.- 从以下版本开始:
- 2.0.0
嵌套类概要
嵌套类 修饰符和类型 类 说明 static class
PropertyMapper.Source<T>
A source that is in the process of being mapped.static interface
PropertyMapper.SourceOperator
An operation that can be applied to aPropertyMapper.Source
.
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 PropertyMapper
alwaysApplying(PropertyMapper.SourceOperator operator)
Return a newPropertyMapper
instance that applies the givenPropertyMapper.SourceOperator
to every source.PropertyMapper
alwaysApplyingWhenNonNull()
Return a newPropertyMapper
instance that applieswhenNonNull
to every source.<T> PropertyMapper.Source<T>
from(Supplier<T> supplier)
Return a newPropertyMapper.Source
from the specified value supplier that can be used to perform the mapping.<T> PropertyMapper.Source<T>
from(T value)
Return a newPropertyMapper.Source
from the specified value that can be used to perform the mapping.static PropertyMapper
get()
Return the property mapper.
方法详细资料
alwaysApplyingWhenNonNull
public PropertyMapper alwaysApplyingWhenNonNull()
Return a newPropertyMapper
instance that applieswhenNonNull
to every source.- 返回:
- a new property mapper instance
alwaysApplying
public PropertyMapper alwaysApplying(PropertyMapper.SourceOperator operator)
Return a newPropertyMapper
instance that applies the givenPropertyMapper.SourceOperator
to every source.- 参数:
operator
- the source operator to apply- 返回:
- a new property mapper instance
from
public <T> PropertyMapper.Source<T> from(Supplier<T> supplier)
Return a newPropertyMapper.Source
from the specified value supplier that can be used to perform the mapping.- 类型参数:
T
- the source type- 参数:
supplier
- the value supplier- 返回:
- a
PropertyMapper.Source
that can be used to complete the mapping - 另请参阅:
from(Object)
from
public <T> PropertyMapper.Source<T> from(T value)
Return a newPropertyMapper.Source
from the specified value that can be used to perform the mapping.- 类型参数:
T
- the source type- 参数:
value
- the value- 返回:
- a
PropertyMapper.Source
that can be used to complete the mapping
get
public static PropertyMapper get()
Return the property mapper.- 返回:
- the property mapper