public final class PropertyMapper extends Object
@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
.
Modifier and Type | Class and Description |
---|---|
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 a
PropertyMapper.Source . |
Modifier and Type | Method and Description |
---|---|
PropertyMapper |
alwaysApplying(PropertyMapper.SourceOperator operator)
Return a new
PropertyMapper instance that applies the given
PropertyMapper.SourceOperator to every source. |
PropertyMapper |
alwaysApplyingWhenNonNull()
Return a new
PropertyMapper instance that applies
whenNonNull to every source. |
<T> PropertyMapper.Source<T> |
from(Supplier<T> supplier)
Return a new
PropertyMapper.Source from the specified value supplier that can be used to
perform the mapping. |
<T> PropertyMapper.Source<T> |
from(T value)
Return a new
PropertyMapper.Source from the specified value that can be used to perform
the mapping. |
static PropertyMapper |
get()
Return the property mapper.
|
public PropertyMapper alwaysApplyingWhenNonNull()
PropertyMapper
instance that applies
whenNonNull
to every source.public PropertyMapper alwaysApplying(PropertyMapper.SourceOperator operator)
PropertyMapper
instance that applies the given
PropertyMapper.SourceOperator
to every source.operator
- the source operator to applypublic <T> PropertyMapper.Source<T> from(Supplier<T> supplier)
PropertyMapper.Source
from the specified value supplier that can be used to
perform the mapping.T
- the source typesupplier
- the value supplierPropertyMapper.Source
that can be used to complete the mappingfrom(Object)
public <T> PropertyMapper.Source<T> from(T value)
PropertyMapper.Source
from the specified value that can be used to perform
the mapping.T
- the source typevalue
- the valuePropertyMapper.Source
that can be used to complete the mappingpublic static PropertyMapper get()
Copyright © 2021 Pivotal Software, Inc.. All rights reserved.