public interface ConfigMapper
Config mapper is provided to
ConfigMapperProvider
to help transformation of
complex structures.-
Method Summary
Modifier and TypeMethodDescription<T> T
map
(Config config, GenericType<T> type) Convert the specifiedConfig
node into the target type specified byGenericType
.<T> T
Converts the specifiedConfig
node to the target type.<T> T
map
(String value, GenericType<T> type, String key) Converts the value to the target generic type.<T> T
Converts the value to the target type.
-
Method Details
-
map
Convert the specifiedConfig
node into the target type specified byGenericType
. You can useGenericType.create(Type)
if needed to wrap a parametrized type.- Type Parameters:
T
- type of the result- Parameters:
config
- config node to converttype
- type to extract generics types from (to prevent type erasure)- Returns:
- converted value, never null
- Throws:
MissingValueException
- in case a value is expected and not found (either on this config node or on a subnode)ConfigMappingException
- in case the config node cannot be converted into the expected type (e.g. value is"hello"
and expected type isList<Integer>
)
-
map
Converts the specifiedConfig
node to the target type.The method uses the mapper function instance associated with the specified
type
to convert theConfig
subtree. If there is none it tries to find one fromConfigMapperProvider.mapper(Class)
from configured mapper providers. If none is found, mapping will throw aConfigMappingException
.- Type Parameters:
T
- type to which the config node is to be transformed- Parameters:
config
- config node to be transformedtype
- type to which the config node is to be transformed- Returns:
- transformed value of type
T
; never returnsnull
- Throws:
MissingValueException
- in case the configuration node does not represent an existing configuration nodeConfigMappingException
- in case the mapper fails to map the existing configuration value to an instance of a given Java type
-
map
<T> T map(String value, Class<T> type, String key) throws MissingValueException, ConfigMappingException Converts the value to the target type.- Type Parameters:
T
- type of the converted value- Parameters:
value
- String value to converttype
- type to convert tokey
- configuration key to be used to create appropriate exceptions- Returns:
- value converted to the correct type
- Throws:
MissingValueException
- iin case a value is expected and not found (e.g. when trying to convert to a complex object)ConfigMappingException
- in case the String cannot be converted to the expected type
-
map
<T> T map(String value, GenericType<T> type, String key) throws MissingValueException, ConfigMappingException Converts the value to the target generic type.- Type Parameters:
T
- type of the converted value- Parameters:
value
- String value to converttype
- generic type to convert tokey
- configuration key to be used to create appropriate exceptions- Returns:
- value converted to the correct type
- Throws:
MissingValueException
- iin case a value is expected and not found (e.g. when trying to convert to a complex object)ConfigMappingException
- in case the String cannot be converted to the expected type
-