ConfigValue representing an object (AKA dictionary or map)
value, as in JSON's curly brace { "a" : 42 } syntax.
An object may also be viewed as a Config by calling
ConfigObject#toConfig().
ConfigObject implements java.util.Map<String, ConfigValue> so
you can use it like a regular Java map. Or call unwrapped() to
unwrap the map to a map with plain Java values rather than
ConfigValue.
Like all ConfigValue subtypes, ConfigObject is immutable.
This makes it threadsafe and you never have to create "defensive copies." The
mutator methods from java. all throw
java..
The ConfigValue#valueType method on an object returns
ConfigValueType#OBJECT.
In most cases you want to use the Config interface rather than this
one. Call toConfig() to convert a ConfigObject to a
Config.
The API for a ConfigObject is in terms of keys, while the API for a
Config is in terms of path expressions. Conceptually,
ConfigObject is a tree of maps from keys to values, while a
Config is a one-level map from paths to values.
Use ConfigUtil#joinPath and ConfigUtil#splitPath to convert
between path expressions and individual path elements (keys).
A ConfigObject may contain null values, which will have
ConfigValue#valueType() equal to ConfigValueType#NULL. If
ConfigObject#get(Object) returns Java's null then the key was not
present in the parsed file (or wherever this value tree came from). If
get("key") returns a ConfigValue with type
ConfigValueType#NULL then the key was set to null explicitly in the
config file.
Do not implement interface ConfigObject; 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.
| Modifier and Type | Method and Description |
|---|---|
| public ConfigValue | Returns: the value at the key or null if nonekey to look up key)Redeclares java. Gets a |
| public Config | |
| public Map | Returns: ajava. containing plain Java objectsRedeclares com. Recursively unwraps the object, returning a map from String to whatever plain Java values are unwrapped from the object's values. |
| public ConfigObject | withFallback(ConfigMergeable
an object whose keys should be used as fallbacks, if the keys
are not present in this one other)Redeclares com. Returns a new value computed by merging this value with another, with keys in this value "winning" over the other one. |
| public ConfigObject | Returns: a copy of the object minus all keys except the one specifiedkey to keep key)Clone the object with only the given key (and its children) retained; all sibling keys are removed. |
| public ConfigObject | withOrigin(ConfigOrigin
the origin set on the returned value origin)Redeclares com. Returns a |
| public ConfigObject | Returns: a copy of the object minus the specified keykey to remove key)Clone the object with the given key removed. |
| public ConfigObject | Returns: the new instance with the new map entrykey to add key, ConfigValue value at the new key value)Returns a |
| get | back to summary |
|---|---|
| public ConfigValue get(Object key) Redeclares java. Gets a
| |
| toConfig | back to summary |
|---|---|
| public Config toConfig() Converts this object to a | |
| unwrapped | back to summary |
|---|---|
| public Map Redeclares com. Recursively unwraps the object, returning a map from String to whatever plain Java values are unwrapped from the object's values.
| |
| withFallback | back to summary |
|---|---|
| public ConfigObject withFallback(ConfigMergeable other) Redeclares com. Doc from com. Returns a new value computed by merging this value with another, with keys in this value "winning" over the other one. This associative operation may be used to combine configurations from multiple sources (such as multiple configuration files). The semantics of merging are described in the spec for HOCON. Merging typically occurs when either the same object is created twice in the same file, or two config files are both loaded. For example:
foo = { a: 42 }
foo = { b: 43 }
Here, the two objects are merged as if you had written:
foo = { a: 42, b: 43 }
Only
foo = { a: 42 }
foo = 10
Here, the number 10 "wins" and the value of foo would be
simply 10. Again, for details see the spec.
| |
| withOnlyKey | back to summary |
|---|---|
| public ConfigObject withOnlyKey(String key) Clone the object with only the given key (and its children) retained; all sibling keys are removed.
| |
| withOrigin | back to summary |
|---|---|
| public ConfigObject withOrigin(ConfigOrigin origin) Redeclares com. Doc from com. Returns a
| |
| withoutKey | back to summary |
|---|---|
| public ConfigObject withoutKey(String key) Clone the object with the given key removed.
| |
| withValue | back to summary |
|---|---|
| public ConfigObject withValue(String key, ConfigValue value) Returns a
| |