Class ConfigValueFactory
- java.lang.Object
-
- com.typesafe.config.ConfigValueFactory
-
public final class ConfigValueFactory extends java.lang.Object
This class holds some static factory methods for buildingConfigValue
instances. See alsoConfigFactory
which has methods for parsing files and certain in-memory data structures.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ConfigValue
fromAnyRef(java.lang.Object object)
See the other overloadfromAnyRef(Object,String)
for details, this one just uses a default origin description.static ConfigValue
fromAnyRef(java.lang.Object object, java.lang.String originDescription)
Creates aConfigValue
from a plain Java boxed value, which may be aBoolean
,Number
,String
,Map
,Iterable
, ornull
.static ConfigList
fromIterable(java.lang.Iterable<? extends java.lang.Object> values)
See the other overload offromIterable(Iterable, String)
for details, this one just uses a default origin description.static ConfigList
fromIterable(java.lang.Iterable<? extends java.lang.Object> values, java.lang.String originDescription)
See thefromAnyRef(Object,String)
documentation for details.static ConfigObject
fromMap(java.util.Map<java.lang.String,? extends java.lang.Object> values)
See the other overloadfromMap(Map,String)
for details, this one just uses a default origin description.static ConfigObject
fromMap(java.util.Map<java.lang.String,? extends java.lang.Object> values, java.lang.String originDescription)
See thefromAnyRef(Object,String)
documentation for details.
-
-
-
Method Detail
-
fromAnyRef
public static ConfigValue fromAnyRef(java.lang.Object object, java.lang.String originDescription)
Creates aConfigValue
from a plain Java boxed value, which may be aBoolean
,Number
,String
,Map
,Iterable
, ornull
. AMap
must be aMap
from String to more values that can be supplied tofromAnyRef()
. AnIterable
must iterate over more values that can be supplied tofromAnyRef()
. AMap
will become aConfigObject
and anIterable
will become aConfigList
. If theIterable
is not an ordered collection, results could be strange, sinceConfigList
is ordered.In a
Map
passed tofromAnyRef()
, the map's keys are plain keys, not path expressions. So if yourMap
has a key "foo.bar" then you will get one object with a key called "foo.bar", rather than an object with a key "foo" containing another object with a key "bar".The originDescription will be used to set the origin() field on the ConfigValue. It should normally be the name of the file the values came from, or something short describing the value such as "default settings". The originDescription is prefixed to error messages so users can tell where problematic values are coming from.
Supplying the result of ConfigValue.unwrapped() to this function is guaranteed to work and should give you back a ConfigValue that matches the one you unwrapped. The re-wrapped ConfigValue will lose some information that was present in the original such as its origin, but it will have matching values.
This function throws if you supply a value that cannot be converted to a ConfigValue, but supplying such a value is a bug in your program, so you should never handle the exception. Just fix your program (or report a bug against this library).
- Parameters:
object
- object to convert to ConfigValueoriginDescription
- name of origin file or brief description of what the value is- Returns:
- a new value
-
fromMap
public static ConfigObject fromMap(java.util.Map<java.lang.String,? extends java.lang.Object> values, java.lang.String originDescription)
See thefromAnyRef(Object,String)
documentation for details. This is a typesafe wrapper that only works onMap
and returnsConfigObject
rather thanConfigValue
.If your
Map
has a key "foo.bar" then you will get one object with a key called "foo.bar", rather than an object with a key "foo" containing another object with a key "bar". The keys in the map are keys; not path expressions. That is, theMap
corresponds exactly to a singleConfigObject
. The keys will not be parsed or modified, and the values are wrapped in ConfigValue. To get nestedConfigObject
, some of the values in the map would have to be more maps.See also
ConfigFactory.parseMap(Map,String)
which interprets the keys in the map as path expressions.- Parameters:
values
-originDescription
-- Returns:
- a new
ConfigObject
value
-
fromIterable
public static ConfigList fromIterable(java.lang.Iterable<? extends java.lang.Object> values, java.lang.String originDescription)
See thefromAnyRef(Object,String)
documentation for details. This is a typesafe wrapper that only works onIterable
and returnsConfigList
rather thanConfigValue
.- Parameters:
values
-originDescription
-- Returns:
- a new
ConfigList
value
-
fromAnyRef
public static ConfigValue fromAnyRef(java.lang.Object object)
See the other overloadfromAnyRef(Object,String)
for details, this one just uses a default origin description.- Parameters:
object
-- Returns:
- a new
ConfigValue
-
fromMap
public static ConfigObject fromMap(java.util.Map<java.lang.String,? extends java.lang.Object> values)
See the other overloadfromMap(Map,String)
for details, this one just uses a default origin description.See also
ConfigFactory.parseMap(Map)
which interprets the keys in the map as path expressions.- Parameters:
values
-- Returns:
- a new
ConfigObject
-
fromIterable
public static ConfigList fromIterable(java.lang.Iterable<? extends java.lang.Object> values)
See the other overload offromIterable(Iterable, String)
for details, this one just uses a default origin description.- Parameters:
values
-- Returns:
- a new
ConfigList
-
-