Config
An immutable map from config paths to config values. Paths are dot-separated
expressions such as foo.bar.baz. Values are as in JSON
(booleans, strings, numbers, lists, or objects), represented by
Config interface are never null.
expressions such as foo.bar.baz. Values are as in JSON
(booleans, strings, numbers, lists, or objects), represented by
[[ConfigValue]]
instances. Values accessed through theConfig interface are never null.
Config is an immutable object and thus safe to use from multiple
threads. There's never a need for "defensive copies."
threads. There's never a need for "defensive copies."
Fundamental operations on a Config include getting configuration
values, resolving substitutions with resolve(), and
merging configs using
withFallback(ConfigMergeable).
values, resolving substitutions with resolve(), and
merging configs using
withFallback(ConfigMergeable).
All operations return a new immutable Config rather than modifying
the original instance.
the original instance.
Examples
You can find an example app and library
on GitHub.
Also be sure to read the
which describes the big picture as shown in those examples.
on GitHub.
Also be sure to read the
package-summary.html#package_description
package overview]]which describes the big picture as shown in those examples.
Paths, keys, and Config vs. ConfigObject
Config is a view onto a tree of
corresponding object tree can be found through
ConfigObject is a map from config keys, rather than
paths, to config values. Think of ConfigObject as a JSON object
and Config as a configuration API.
[[ConfigObject]]
; thecorresponding object tree can be found through
[[Config#root]]
.ConfigObject is a map from config keys, rather than
paths, to config values. Think of ConfigObject as a JSON object
and Config as a configuration API.
The API tries to consistently use the terms "key" and "path." A key is a key
in a JSON object; it's just a string that's the key in a map. A "path" is a
parseable expression with a syntax and it refers to a series of keys. Path
expressions are described in the
spec for Human-Optimized Config Object Notation.
In brief, a path is
period-separated so "a.b.c" looks for key c in object b in object a in the
root object. Sometimes double quotes are needed around special characters in
path expressions.
in a JSON object; it's just a string that's the key in a map. A "path" is a
parseable expression with a syntax and it refers to a series of keys. Path
expressions are described in the
spec for Human-Optimized Config Object Notation.
In brief, a path is
period-separated so "a.b.c" looks for key c in object b in object a in the
root object. Sometimes double quotes are needed around special characters in
path expressions.
The API for a Config is in terms of path expressions, while the API
for a ConfigObject is in terms of keys. Conceptually, Config
is a one-level map from paths to values, while a
ConfigObject is a tree of nested maps from keys to values.
for a ConfigObject is in terms of keys. Conceptually, Config
is a one-level map from paths to values, while a
ConfigObject is a tree of nested maps from keys to values.
Use ConfigUtil.joinPath(String*)
and ConfigUtil.splitPath(String)
to convert between path expressions and individual path elements (keys).
and ConfigUtil.splitPath(String)
to convert between path expressions and individual path elements (keys).
Another difference between Config and ConfigObject is that
conceptually, ConfigValues with a
ConfigObject, while a Config treats null values as if they
were missing. (With the exception of two methods:
and
conceptually, ConfigValues with a
[[ConfigValue#valueType
valueType]]
of [[ConfigValueType#NULL NULL]]
exist in aConfigObject, while a Config treats null values as if they
were missing. (With the exception of two methods:
[[Config#hasPathOrNull]]
and
[[Config#getIsNull]]
let you detect null values.)Getting configuration values
The "getters" on a Config all work in the same way. They never return
null, nor do they return a ConfigValue with
completely absent or set to null. If the value is set to null, a subtype of
ConfigException.Missing called
thrown.
a type and the value has an incompatible type. Reasonable type conversions
are performed for you though.
null, nor do they return a ConfigValue with
[[ConfigValue#valueType valueType]]
of [[ConfigValueType#NULL
NULL]]
. Instead, they throw [[ConfigException.Missing]]
if the value iscompletely absent or set to null. If the value is set to null, a subtype of
ConfigException.Missing called
[[ConfigException.Null]]
will bethrown.
[[ConfigException.WrongType]]
will be thrown anytime you ask fora type and the value has an incompatible type. Reasonable type conversions
are performed for you though.
Iteration
If you want to iterate over the contents of a Config, you can get its
ConfigObject with
ConfigObject (which implements java.util.Map). Or, you
can use
up a Set of all path-value pairs where the value is not null.
ConfigObject with
[[#root]]
, and then iterate over theConfigObject (which implements java.util.Map). Or, you
can use
[[#entrySet]]
which recurses the object tree for you and buildsup a Set of all path-value pairs where the value is not null.
'''Resolving substitutions'''
''Substitutions'' are the
files, described in the <a href=
"https://github.com/lightbend/config/blob/master/HOCON.md#substitutions"
${foo.bar}
syntax in configfiles, described in the <a href=
"https://github.com/lightbend/config/blob/master/HOCON.md#substitutions"
specification. Resolving substitutions replaces these references with real
values.
Before using a Config it's necessary to call resolve()
to handle substitutions (though ConfigFactory.load() and similar
methods will do the resolve for you already).
to handle substitutions (though ConfigFactory.load() and similar
methods will do the resolve for you already).
Merging
The full Config for your application can be constructed using
the associative operation
withFallback(ConfigMergeable).
If you use ConfigFactory.load() (recommended), it
merges system properties over the top of application.conf over
the top of reference.conf, using withFallback. You
can add in additional sources of configuration in the same way (usually,
custom layers should go either just above or just below
application.conf, keeping reference.conf at the
bottom and system properties at the top).
the associative operation
withFallback(ConfigMergeable).
If you use ConfigFactory.load() (recommended), it
merges system properties over the top of application.conf over
the top of reference.conf, using withFallback. You
can add in additional sources of configuration in the same way (usually,
custom layers should go either just above or just below
application.conf, keeping reference.conf at the
bottom and system properties at the top).
Serialization
Convert a Config to a JSON or HOCON string by calling
root to get the ConfigObject and then call
render
on the root object, myConfig.root.render. There's also a variant
render(ConfigRenderOptions)
inherited from ConfigValue which allows you to control
the format of the rendered string. (See
that Config does not remember the formatting of the original
file, so if you load, modify, and re-save a config file, it will be
substantially reformatted.
root to get the ConfigObject and then call
render
on the root object, myConfig.root.render. There's also a variant
render(ConfigRenderOptions)
inherited from ConfigValue which allows you to control
the format of the rendered string. (See
[[ConfigRenderOptions]]
.) Notethat Config does not remember the formatting of the original
file, so if you load, modify, and re-save a config file, it will be
substantially reformatted.
As an alternative to render, the
toString method produces a debug-output-oriented
representation (which is not valid JSON).
toString method produces a debug-output-oriented
representation (which is not valid JSON).
Java serialization is supported as well for Config and all
subtypes of ConfigValue.
subtypes of ConfigValue.
This is an interface but don't implement it yourself
Do not implement Config; it should only be implemented by
the config library. Arbitrary implementations will not work because the
library internals assume a specific concrete implementation. Also, this
interface is likely to grow new methods over time, so third-party
implementations will break.
the config library. Arbitrary implementations will not work because the
library internals assume a specific concrete implementation. Also, this
interface is likely to grow new methods over time, so third-party
implementations will break.
Value members
Methods
Gets the Config as a tree of
constant-time operation (it is not proportional to the number of values
in the Config).
[[ConfigObject]]
. This is aconstant-time operation (it is not proportional to the number of values
in the Config).
- Returns
-
the root object in the configuration
Gets the origin of the Config, which may be a file, or a file
with a line number, or just a descriptive phrase.
with a line number, or just a descriptive phrase.
- Returns
-
the origin of the Config for use in error messages
Returns a replacement config with all substitutions (the
HOCON spec
for resolved. Substitutions are looked up using this
${foo.bar}
syntax, seeHOCON spec
for resolved. Substitutions are looked up using this
Config
as the root object, that is, a substitution${foo.bar}
will be replaced with the result ofgetValue("foo.bar")
.This method uses
another variant
resolve(ConfigResolveOptions)
which lets you specify non-default options.
[[ConfigResolveOptions#defaults]]
, there isanother variant
resolve(ConfigResolveOptions)
which lets you specify non-default options.
A given
config values, but ideally should be resolved one time for your entire
stack of fallbacks (see
substitutions that could have resolved with all fallbacks available may
not resolve, which will be potentially confusing for your application's
users.
[[Config]]
must be resolved before using it to retrieveconfig values, but ideally should be resolved one time for your entire
stack of fallbacks (see
[[Config#withFallback]]
). Otherwise, somesubstitutions that could have resolved with all fallbacks available may
not resolve, which will be potentially confusing for your application's
users.
resolve should be invoked on root config objects, rather
than on a subtree (a subtree is the result of something like
config.getConfig("foo")). The problem with
resolve on a subtree is that substitutions are relative to
the root of the config and the subtree will have no way to get values
from the root. For example, if you did
config.getConfig("foo").resolve on the below config file,
it would not work:
than on a subtree (a subtree is the result of something like
config.getConfig("foo")). The problem with
resolve on a subtree is that substitutions are relative to
the root of the config and the subtree will have no way to get values
from the root. For example, if you did
config.getConfig("foo").resolve on the below config file,
it would not work:
{{{
common-value = 10
foo {
whatever = ${common-value}
}
}}}
common-value = 10
foo {
whatever = ${common-value}
}
}}}
Many methods on
ConfigFactory.load() automatically resolve the
loaded Config on the loaded stack of config files.
[[ConfigFactory]]
such asConfigFactory.load() automatically resolve the
loaded Config on the loaded stack of config files.
Resolving an already-resolved config is a harmless no-op, but again, it
is best to resolve an entire stack of fallbacks (such as all your config
files combined) rather than resolving each one individually.
is best to resolve an entire stack of fallbacks (such as all your config
files combined) rather than resolving each one individually.
- Returns
-
an immutable object with substitutions resolved
- Throws
- ConfigException
- ConfigException
- ConfigException.UnresolvedSubstitution
- ConfigException.UnresolvedSubstitution
Like resolve() but allows you to specify non-default
options.
options.
- Value Params
- options
-
resolve options
- Returns
-
the resolved Config (may be only partially resolved if options are set to allow unresolved)
Checks whether the config is completely resolved. After a successful call
to resolve() it will be completely resolved, but after calling
resolve(ConfigResolveOptions)
with allowUnresolved set in the options, it may or may not be
completely resolved. A newly-loaded config may or may not be completely
resolved depending on whether there were substitutions present in the
file.
to resolve() it will be completely resolved, but after calling
resolve(ConfigResolveOptions)
with allowUnresolved set in the options, it may or may not be
completely resolved. A newly-loaded config may or may not be completely
resolved depending on whether there were substitutions present in the
file.
- Returns
-
true if there are no unresolved substitutions remaining in this
configuration. - Since
-
1.2.0
Like resolve() except that substitution values are looked
up in the given source, rather than in this instance. This is a
special-purpose method which doesn't make sense to use in most cases;
it's only needed if you're constructing some sort of app-specific custom
approach to configuration. The more usual approach if you have a source
of substitution values would be to merge that source into your config
stack using
up in the given source, rather than in this instance. This is a
special-purpose method which doesn't make sense to use in most cases;
it's only needed if you're constructing some sort of app-specific custom
approach to configuration. The more usual approach if you have a source
of substitution values would be to merge that source into your config
stack using
[[Config#withFallback]]
and then resolve.Note that this method does NOT look in this instance for substitution
values. If you want to do that, you could either merge this instance into
your value source using
multiple times with multiple sources (using
resolves don't fail).
values. If you want to do that, you could either merge this instance into
your value source using
[[Config#withFallback]]
, or you could resolvemultiple times with multiple sources (using
[[ConfigResolveOptions#setAllowUnresolved]]
so the partialresolves don't fail).
- Value Params
- source
-
configuration to pull values from
- Returns
-
an immutable object with substitutions resolved
- Throws
- ConfigException
- ConfigException
- ConfigException.UnresolvedSubstitution
- ConfigException.UnresolvedSubstitution
- Since
-
1.2.0
Like resolveWith(Config)
but allows you to specify non-default options.
but allows you to specify non-default options.
- Value Params
- options
-
resolve options
- source
-
source configuration to pull values from
- Returns
-
the resolved Config (may be only partially resolved
if options are set to allow unresolved) - Since
-
1.2.0
@varargs
Validates this config against a reference config, throwing an exception
if it is invalid. The purpose of this method is to "fail early" with a
comprehensive list of problems; in general, anything this method can find
would be detected later when trying to use the config, but it's often
more user-friendly to fail right away when loading the config.
if it is invalid. The purpose of this method is to "fail early" with a
comprehensive list of problems; in general, anything this method can find
would be detected later when trying to use the config, but it's often
more user-friendly to fail right away when loading the config.
Using this method is always optional, since you can "fail late" instead.
You must restrict validation to paths you "own" (those whose meaning are
defined by your code module). If you validate globally, you may trigger
errors about paths that happen to be in the config but have nothing to do
with your module. It's best to allow the modules owning those paths to
validate them. Also, if every module validates only its own stuff, there
isn't as much redundant work being done.
defined by your code module). If you validate globally, you may trigger
errors about paths that happen to be in the config but have nothing to do
with your module. It's best to allow the modules owning those paths to
validate them. Also, if every module validates only its own stuff, there
isn't as much redundant work being done.
If no paths are specified in checkValid's parameter list,
validation is for the entire config.
validation is for the entire config.
If you specify paths that are not in the reference config, those paths
are ignored. (There's nothing to validate.)
are ignored. (There's nothing to validate.)
Here's what validation involves:
-
All paths found in the reference config must be present in this
config or an exception will be thrown.
-
Some changes in type from the reference config to this config will cause
an exception to be thrown. Not all potential type problems are detected,
in particular it's assumed that strings are compatible with everything
except objects and lists. This is because string types are often "really"
some other type (system properties always start out as strings, or a
string like "5ms" could be used with
getDuration(String)).
Also, it's allowed to set any type to null or override null with any type.
Some changes in type from the reference config to this config will cause
an exception to be thrown. Not all potential type problems are detected,
in particular it's assumed that strings are compatible with everything
except objects and lists. This is because string types are often "really"
some other type (system properties always start out as strings, or a
string like "5ms" could be used with
getDuration(String)).
Also, it's allowed to set any type to null or override null with any type.
-
Any unresolved substitutions in this config will cause a validation
failure; both the reference config and this config should be resolved
before validation. If the reference config is unresolved, it's a bug in
the caller of this method.
Any unresolved substitutions in this config will cause a validation
failure; both the reference config and this config should be resolved
before validation. If the reference config is unresolved, it's a bug in
the caller of this method.
If you want to allow a certain setting to have a flexible type (or
otherwise want validation to be looser for some settings), you could
either remove the problematic setting from the reference config provided
to this method, or you could intercept the validation exception and
screen out certain problems. Of course, this will only work if all other
callers of this method are careful to restrict validation to their own
paths, as they should be.
otherwise want validation to be looser for some settings), you could
either remove the problematic setting from the reference config provided
to this method, or you could intercept the validation exception and
screen out certain problems. Of course, this will only work if all other
callers of this method are careful to restrict validation to their own
paths, as they should be.
If validation fails, the thrown exception contains a list of all problems
found. See
exception's getMessage will have all the problems
concatenated into one huge string, as well.
found. See
[[ConfigException.ValidationFailed#problems]]
. Theexception's getMessage will have all the problems
concatenated into one huge string, as well.
Again, checkValid can't guess every domain-specific way a
setting can be invalid, so some problems may arise later when attempting
to use the config. checkValid is limited to reporting
generic, but common, problems such as missing settings and blatant type
incompatibilities.
setting can be invalid, so some problems may arise later when attempting
to use the config. checkValid is limited to reporting
generic, but common, problems such as missing settings and blatant type
incompatibilities.
- Value Params
- reference
-
a reference configuration
- restrictToPaths
-
only validate values underneath these paths that your code
module owns and understands
- Throws
- ConfigException.BugOrBroken
- ConfigException.BugOrBroken
- ConfigException.NotResolved
- ConfigException.NotResolved
- ConfigException.ValidationFailed
- ConfigException.ValidationFailed
Checks whether a value is present and non-null at the given path. This
differs in two ways from Map.containsKey as implemented by
returns false for null values, while containsKey returns true
indicating that the object contains a null value for the key.
differs in two ways from Map.containsKey as implemented by
[[ConfigObject]]
: it looks for a path expression, not a key; and itreturns false for null values, while containsKey returns true
indicating that the object contains a null value for the key.
If a path exists according to
typed getters, such as
value is not convertible to the requested type.
[[#hasPath]]
, then[[#getValue]]
will never throw an exception. However, thetyped getters, such as
[[#getInt]]
, will still throw if thevalue is not convertible to the requested type.
Note that path expressions have a syntax and sometimes require quoting
(see ConfigUtil$.joinPath and
(see ConfigUtil$.joinPath and
[[ConfigUtil#splitPath]]
).- Value Params
- path
-
the path expression
- Returns
-
true if a non-null value is present at the path
- Throws
- ConfigException.BadPath
- ConfigException.BadPath
Checks whether a value is present at the given path, even
if the value is null. Most of the getters on
Config will throw if you try to get a null
value, so if you plan to call
use plain
if the value is null. Most of the getters on
Config will throw if you try to get a null
value, so if you plan to call
[[#getValue]]
,[[#getInt]]
, or another getter you may want touse plain
[[#hasPath]]
rather than this method.To handle all three cases (unset, null, and a non-null value)
the code might look like:
{{{
if (config.hasPathOrNull(path)) {
if (config.getIsNull(path)) {
// handle null setting
} else {
// get and use non-null setting
}
} else {
// handle entirely unset path
}
}}}
the code might look like:
{{{
if (config.hasPathOrNull(path)) {
if (config.getIsNull(path)) {
// handle null setting
} else {
// get and use non-null setting
}
} else {
// handle entirely unset path
}
}}}
However, the usual thing is to allow entirely unset
paths to be a bug that throws an exception (because you set
a default in your reference.conf), so in that
case it's OK to call
checking hasPathOrNull first.
paths to be a bug that throws an exception (because you set
a default in your reference.conf), so in that
case it's OK to call
[[#getIsNull]]
withoutchecking hasPathOrNull first.
Note that path expressions have a syntax and sometimes require quoting
(see ConfigUtil$.joinPath and
(see ConfigUtil$.joinPath and
[[ConfigUtil#splitPath]]
).- Value Params
- path
-
the path expression
- Returns
-
true if a value is present at the path, even if the value is null
- Throws
- ConfigException.BadPath
- ConfigException.BadPath
Returns true if the Config's root object contains no key-value
pairs.
pairs.
- Returns
-
true if the configuration is empty
Returns the set of path-value pairs, excluding any null values, found by
recursing
different from root.entrySet which returns the set of
immediate-child keys in the root object and includes null values.
recursing
[[#root the root object]]
. Note that this is verydifferent from root.entrySet which returns the set of
immediate-child keys in the root object and includes null values.
Entries contain path expressions meaning there may be quoting
and escaping involved. Parse path expressions with
and escaping involved. Parse path expressions with
[[ConfigUtil#splitPath]]
.Because a Config is conceptually a single-level map from
paths to values, there will not be any
entries (that is, all entries represent leaf nodes). Use
(OK, this is a slight lie: Config entries may contain
directly included as entry values.)
paths to values, there will not be any
[[ConfigObject]]
values in theentries (that is, all entries represent leaf nodes). Use
[[ConfigObject]]
rather than Config if you want a tree.(OK, this is a slight lie: Config entries may contain
[[ConfigList]]
and the lists may contain objects. But no objects aredirectly included as entry values.)
- Returns
-
set of paths with non-null values, built up by recursing the
entire tree of { @link ConfigObject} and creating an entry for
each leaf value.
Checks whether a value is set to null at the given path,
but throws an exception if the value is entirely
unset. This method will not throw if
returned true for the same path, so to avoid any possible exception check
hasPathOrNull first. However, an exception
for unset paths will usually be the right thing (because a
reference.conf should exist that has the path
set, the path should never be unset unless something is
broken).
but throws an exception if the value is entirely
unset. This method will not throw if
[[#hasPathOrNull]]
returned true for the same path, so to avoid any possible exception check
hasPathOrNull first. However, an exception
for unset paths will usually be the right thing (because a
reference.conf should exist that has the path
set, the path should never be unset unless something is
broken).
Note that path expressions have a syntax and sometimes require quoting
(see ConfigUtil$.joinPath and
(see ConfigUtil$.joinPath and
[[ConfigUtil#splitPath]]
).- Value Params
- path
-
the path expression
- Returns
-
true if the value exists and is null, false if it
exists and is not null - Throws
- ConfigException.BadPath
- ConfigException.BadPath
- ConfigException.Missing
- ConfigException.Missing
- Value Params
- path
-
path expression
- Returns
-
the boolean value at the requested path
- Throws
- ConfigException.Missing
- ConfigException.Missing
- ConfigException.WrongType
- ConfigException.WrongType
- Value Params
- path
-
path expression
- Returns
-
the numeric value at the requested path
- Throws
- ConfigException.Missing
- ConfigException.Missing
- ConfigException.WrongType
- ConfigException.WrongType
Gets the integer at the given path. If the value at the
path has a fractional (floating point) component, it
will be discarded and only the integer part will be
returned (it works like a "narrowing primitive conversion"
in the Java language specification).
path has a fractional (floating point) component, it
will be discarded and only the integer part will be
returned (it works like a "narrowing primitive conversion"
in the Java language specification).
- Value Params
- path
-
path expression
- Returns
-
the 32-bit integer value at the requested path
- Throws
- ConfigException.Missing
- ConfigException.Missing
- ConfigException.WrongType
- ConfigException.WrongType
Gets the long integer at the given path. If the value at
the path has a fractional (floating point) component, it
will be discarded and only the integer part will be
returned (it works like a "narrowing primitive conversion"
in the Java language specification).
the path has a fractional (floating point) component, it
will be discarded and only the integer part will be
returned (it works like a "narrowing primitive conversion"
in the Java language specification).
- Value Params
- path
-
path expression
- Returns
-
the 64-bit long value at the requested path
- Throws
- ConfigException.Missing
- ConfigException.Missing
- ConfigException.WrongType
- ConfigException.WrongType
- Value Params
- path
-
path expression
- Returns
-
the floating-point value at the requested path
- Throws
- ConfigException.Missing
- ConfigException.Missing
- ConfigException.WrongType
- ConfigException.WrongType
- Value Params
- path
-
path expression
- Returns
-
the string value at the requested path
- Throws
- ConfigException.Missing
- ConfigException.Missing
- ConfigException.WrongType
- ConfigException.WrongType
- Value Params
- <
-
T>
a generic denoting a specific type of enum - enumClass
-
an enum class
- path
-
path expression
- Returns
-
the { @code Enum} value at the requested path
of the requested enum class - Throws
- ConfigException.Missing
- ConfigException.Missing
- ConfigException.WrongType
- ConfigException.WrongType
- Value Params
- path
-
path expression
- Returns
-
the { @link ConfigObject} value at the requested path
- Throws
- ConfigException.Missing
- ConfigException.Missing
- ConfigException.WrongType
- ConfigException.WrongType
- Value Params
- path
-
path expression
- Returns
-
the nested Config value at the requested path
- Throws
- ConfigException.Missing
- ConfigException.Missing
- ConfigException.WrongType
- ConfigException.WrongType
Gets the value at the path as an unwrapped Java boxed value (
so on - see
java.lang.Boolean
java.lang.Integer
, andso on - see
[[ConfigValue#unwrapped]]
).- Value Params
- path
-
path expression
- Returns
-
the unwrapped value at the requested path
- Throws
- ConfigException.Missing
- ConfigException.Missing
Gets the value at the given path, unless the value is a
null value or missing, in which case it throws just like
the other getters. Use get on the
object (or other object in the tree) if you
want an unprocessed value.
null value or missing, in which case it throws just like
the other getters. Use get on the
[[Config#root]]
object (or other object in the tree) if you
want an unprocessed value.
- Value Params
- path
-
path expression
- Returns
-
the value at the requested path
- Throws
- ConfigException.Missing
- ConfigException.Missing
Gets a value as a size in bytes (parses special strings like "128M"). If
the value is already a number, then it's left alone; if it's a string,
it's parsed understanding unit suffixes such as "128K", as documented in
the the spec.
the value is already a number, then it's left alone; if it's a string,
it's parsed understanding unit suffixes such as "128K", as documented in
the the spec.
- Value Params
- path
-
path expression
- Returns
-
the value at the requested path, in bytes
- Throws
- ConfigException.BadValue
- ConfigException.BadValue
- ConfigException.Missing
- ConfigException.Missing
- ConfigException.WrongType
- ConfigException.WrongType
Gets a value as an amount of memory (parses special strings like "128M"). If
the value is already a number, then it's left alone; if it's a string,
it's parsed understanding unit suffixes such as "128K", as documented in
the the spec.
the value is already a number, then it's left alone; if it's a string,
it's parsed understanding unit suffixes such as "128K", as documented in
the the spec.
- Value Params
- path
-
path expression
- Returns
-
the value at the requested path, in bytes
- Throws
- ConfigException.BadValue
- ConfigException.BadValue
- ConfigException.Missing
- ConfigException.Missing
- ConfigException.WrongType
- ConfigException.WrongType
- Since
-
1.3.0
Gets a value as a duration in a specified
number, then it's taken as milliseconds and then converted to the
requested TimeUnit; if it's a string, it's parsed understanding units
suffixes like "10m" or "5ns" as documented in the <a
the HOCON spec.
java.util.concurrent.TimeUnit
. If the value is already anumber, then it's taken as milliseconds and then converted to the
requested TimeUnit; if it's a string, it's parsed understanding units
suffixes like "10m" or "5ns" as documented in the <a
the HOCON spec.
- Value Params
- path
-
path expression
- unit
-
convert the return value to this time unit
- Returns
-
the duration value at the requested path, in the given TimeUnit
- Throws
- ConfigException.BadValue
- ConfigException.BadValue
- ConfigException.Missing
- ConfigException.Missing
- ConfigException.WrongType
- ConfigException.WrongType
- Since
-
1.2.0
Gets a value as a java.time.Duration. If the value is
already a number, then it's taken as milliseconds; if it's
a string, it's parsed understanding units suffixes like
"10m" or "5ns" as documented in the the
spec. This method never returns null.
already a number, then it's taken as milliseconds; if it's
a string, it's parsed understanding units suffixes like
"10m" or "5ns" as documented in the the
spec. This method never returns null.
- Value Params
- path
-
path expression
- Returns
-
the duration value at the requested path
- Throws
- ConfigException.BadValue
- ConfigException.BadValue
- ConfigException.Missing
- ConfigException.Missing
- ConfigException.WrongType
- ConfigException.WrongType
- Since
-
1.3.0
Gets a value as a java.time.Period. If the value is
already a number, then it's taken as days; if it's
a string, it's parsed understanding units suffixes like
"10d" or "5w" as documented in the the
spec. This method never returns null.
already a number, then it's taken as days; if it's
a string, it's parsed understanding units suffixes like
"10d" or "5w" as documented in the the
spec. This method never returns null.
- Value Params
- path
-
path expression
- Returns
-
the period value at the requested path
- Throws
- ConfigException.BadValue
- ConfigException.BadValue
- ConfigException.Missing
- ConfigException.Missing
- ConfigException.WrongType
- ConfigException.WrongType
- Since
-
1.3.0
Gets a value as a java.time.temporal.TemporalAmount.
This method will first try get get the value as a java.time.Duration, and if unsuccessful,
then as a java.time.Period.
This means that values like "5m" will be parsed as 5 minutes rather than 5 months
This method will first try get get the value as a java.time.Duration, and if unsuccessful,
then as a java.time.Period.
This means that values like "5m" will be parsed as 5 minutes rather than 5 months
- Value Params
- path
-
path expression
- Returns
-
the temporal value at the requested path
- Throws
- ConfigException.BadValue
- ConfigException.BadValue
- ConfigException.Missing
- ConfigException.Missing
- ConfigException.WrongType
- ConfigException.WrongType
Gets a list value (with any element type) as a
implements java.util.List. Throws if the path is
unset or null.
[[ConfigList]]
, whichimplements java.util.List. Throws if the path is
unset or null.
- Value Params
- path
-
the path to the list value.
- Returns
-
the { @link ConfigList} at the path
- Throws
- ConfigException.Missing
- ConfigException.Missing
- ConfigException.WrongType
- ConfigException.WrongType
Gets a list value with boolean elements. Throws if the
path is unset or null or not a list or contains values not
convertible to boolean.
path is unset or null or not a list or contains values not
convertible to boolean.
- Value Params
- path
-
the path to the list value.
- Returns
-
the list at the path
- Throws
- ConfigException.Missing
- ConfigException.Missing
- ConfigException.WrongType
- ConfigException.WrongType
Gets a list value with number elements. Throws if the
path is unset or null or not a list or contains values not
convertible to number.
path is unset or null or not a list or contains values not
convertible to number.
- Value Params
- path
-
the path to the list value.
- Returns
-
the list at the path
- Throws
- ConfigException.Missing
- ConfigException.Missing
- ConfigException.WrongType
- ConfigException.WrongType
Gets a list value with int elements. Throws if the
path is unset or null or not a list or contains values not
convertible to int.
path is unset or null or not a list or contains values not
convertible to int.
- Value Params
- path
-
the path to the list value.
- Returns
-
the list at the path
- Throws
- ConfigException.Missing
- ConfigException.Missing
- ConfigException.WrongType
- ConfigException.WrongType
Gets a list value with long elements. Throws if the
path is unset or null or not a list or contains values not
convertible to long.
path is unset or null or not a list or contains values not
convertible to long.
- Value Params
- path
-
the path to the list value.
- Returns
-
the list at the path
- Throws
- ConfigException.Missing
- ConfigException.Missing
- ConfigException.WrongType
- ConfigException.WrongType
Gets a list value with double elements. Throws if the
path is unset or null or not a list or contains values not
convertible to double.
path is unset or null or not a list or contains values not
convertible to double.
- Value Params
- path
-
the path to the list value.
- Returns
-
the list at the path
- Throws
- ConfigException.Missing
- ConfigException.Missing
- ConfigException.WrongType
- ConfigException.WrongType
Gets a list value with string elements. Throws if the
path is unset or null or not a list or contains values not
convertible to string.
path is unset or null or not a list or contains values not
convertible to string.
- Value Params
- path
-
the path to the list value.
- Returns
-
the list at the path
- Throws
- ConfigException.Missing
- ConfigException.Missing
- ConfigException.WrongType
- ConfigException.WrongType
Gets a list value with Enum elements. Throws if the
path is unset or null or not a list or contains values not
convertible to Enum.
path is unset or null or not a list or contains values not
convertible to Enum.
- Value Params
- <
-
T>
a generic denoting a specific type of enum - enumClass
-
the enum class
- path
-
the path to the list value.
- Returns
-
the list at the path
- Throws
- ConfigException.Missing
- ConfigException.Missing
- ConfigException.WrongType
- ConfigException.WrongType
Gets a list value with object elements. Throws if the
path is unset or null or not a list or contains values not
convertible to ConfigObject.
path is unset or null or not a list or contains values not
convertible to ConfigObject.
- Value Params
- path
-
the path to the list value.
- Returns
-
the list at the path
- Throws
- ConfigException.Missing
- ConfigException.Missing
- ConfigException.WrongType
- ConfigException.WrongType
Gets a list value with Config elements.
Throws if the path is unset or null or not a list or
contains values not convertible to Config.
Throws if the path is unset or null or not a list or
contains values not convertible to Config.
- Value Params
- path
-
the path to the list value.
- Returns
-
the list at the path
- Throws
- ConfigException.Missing
- ConfigException.Missing
- ConfigException.WrongType
- ConfigException.WrongType
Gets a list value with any kind of elements. Throws if the
path is unset or null or not a list. Each element is
"unwrapped" (see
path is unset or null or not a list. Each element is
"unwrapped" (see
[[ConfigValue#unwrapped]]
).- Value Params
- path
-
the path to the list value.
- Returns
-
the list at the path
- Throws
- ConfigException.Missing
- ConfigException.Missing
- ConfigException.WrongType
- ConfigException.WrongType
Gets a list value with elements representing a size in
bytes. Throws if the path is unset or null or not a list
or contains values not convertible to memory sizes.
bytes. Throws if the path is unset or null or not a list
or contains values not convertible to memory sizes.
- Value Params
- path
-
the path to the list value.
- Returns
-
the list at the path
- Throws
- ConfigException.Missing
- ConfigException.Missing
- ConfigException.WrongType
- ConfigException.WrongType
Gets a list, converting each value in the list to a memory size, using the
same rules as
same rules as
[[#getMemorySize]]
.- Value Params
- path
-
a path expression
- Returns
-
list of memory sizes
- Throws
- ConfigException.Missing
- ConfigException.Missing
- ConfigException.WrongType
- ConfigException.WrongType
- Since
-
1.3.0
Gets a list, converting each value in the list to a duration, using the
same rules as
getDuration(String, TimeUnit).
same rules as
getDuration(String, TimeUnit).
- Value Params
- path
-
a path expression
- unit
-
time units of the returned values
- Returns
-
list of durations, in the requested units
- Since
-
1.2.0
Gets a list, converting each value in the list to a duration, using the
same rules as getDuration(String).
same rules as getDuration(String).
- Value Params
- path
-
a path expression
- Returns
-
list of durations
- Since
-
1.3.0
Clone the config with only the given path (and its children) retained;
all sibling paths are removed.
all sibling paths are removed.
Note that path expressions have a syntax and sometimes require quoting
(see ConfigUtil$.joinPath and
(see ConfigUtil$.joinPath and
[[ConfigUtil#splitPath]]
).- Value Params
- path
-
path to keep
- Returns
-
a copy of the config minus all paths except the one specified
Clone the config with the given path removed.
Note that path expressions have a syntax and sometimes require quoting
(see ConfigUtil$.joinPath and
(see ConfigUtil$.joinPath and
[[ConfigUtil#splitPath]]
).- Value Params
- path
-
path expression to remove
- Returns
-
a copy of the config minus the specified path
Places the config inside another Config at the given path.
Note that path expressions have a syntax and sometimes require quoting
(see ConfigUtil$.joinPath and
(see ConfigUtil$.joinPath and
[[ConfigUtil#splitPath]]
).- Value Params
- path
-
path expression to store this config at.
- Returns
-
a { @code Config} instance containing this config at the given
path.
Places the config inside a Config at the given key. See also
atPath. Note that a key is NOT a path expression (see
ConfigUtil$.joinPath and
atPath. Note that a key is NOT a path expression (see
ConfigUtil$.joinPath and
[[ConfigUtil#splitPath]]
).- Value Params
- key
-
key to store this config at.
- Returns
-
a Config instance containing this config at the given
key.
Returns a Config based on this one, but with the given path set
to the given value. Does not modify this instance (since it's immutable).
If the path already has a value, that value is replaced. To remove a
value, use withoutPath.
to the given value. Does not modify this instance (since it's immutable).
If the path already has a value, that value is replaced. To remove a
value, use withoutPath.
Note that path expressions have a syntax and sometimes require quoting
(see ConfigUtil$.joinPath and
(see ConfigUtil$.joinPath and
[[ConfigUtil#splitPath]]
).- Value Params
- path
-
path expression for the value's new location
- value
-
value at the new path
- Returns
-
the new instance with the new map entry