Package org.openhab.core.config.core
Class ConfigParser
java.lang.Object
org.openhab.core.config.core.ConfigParser
Map an OSGi configuration map
Map<String, Object>
or type-less value to an individual configuration bean or
typed value.- Author:
- David Graeff - Initial contribution, Jan N. Klug - Extended and refactored to an exposed utility class
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> @Nullable T
configurationAs
(Map<String, @Nullable Object> properties, Class<T> configurationClass) Use this method to automatically map a configuration collection to a Configuration holder object.static <T> @Nullable T
Convert a value to a given typestatic <T> T
valueAsOrElse
(@Nullable Object value, Class<T> type, T defaultValue) Convert a value to a given type or return default value
-
Method Details
-
configurationAs
public static <T> @Nullable T configurationAs(Map<String, @Nullable Object> properties, Class<T> configurationClass) Use this method to automatically map a configuration collection to a Configuration holder object. A common use-case would be within a service. Usage example:public void modified(Map<String, Object> properties) { YourConfig config = ConfigParser.configurationAs(properties, YourConfig.class); }
- Parameters:
properties
- The configuration map.configurationClass
- The configuration holder class. An instance of this will be created so make sure that a default constructor is available.- Returns:
- The configuration holder object. All fields that matched a configuration option are set. If a required field is not set, null is returned.
-
valueAsOrElse
Convert a value to a given type or return default value- Parameters:
value
- input value or String representation of that valuetype
- desired target classdefaultValue
- default value to be used if conversion fails or input value is null- Returns:
- the converted value or the default value if value is null or conversion fails
-
valueAs
Convert a value to a given type- Parameters:
value
- input value or String representation of that valuetype
- desired target class- Returns:
- the converted value or null if conversion fails or input value is null
-