Top Description Constructors Methods
com.typesafe.config

public final Class ConfigValueFactory

extends Object
Class Inheritance
Imports
java.util.Map, com.typesafe.config.impl.ConfigImpl

This class holds some static factory methods for building ConfigValue instances. See also ConfigFactory which has methods for parsing files and certain in-memory data structures.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static ConfigValue

Returns:

a new value
fromAnyRef
(Object
object to convert to ConfigValue
object
,
String
name of origin file or brief description of what the value is
originDescription
)

Creates a ConfigValue from a plain Java boxed value, which may be a Boolean, Number, String, Map, Iterable, or null.

public static ConfigValue

Returns:

a new ConfigValue
fromAnyRef
(Object
a plain Java value
object
)

See the other overload fromAnyRef(Object, String) for details, this one just uses a default origin description.

public static ConfigList

Returns:

a new ConfigList value
fromIterable
(Iterable<? extends Object>
list of plain Java values
values
,
String
description to use in ConfigOrigin of created values
originDescription
)

See the fromAnyRef(Object, String) documentation for details.

public static ConfigList

Returns:

a new ConfigList
fromIterable
(Iterable<? extends Object>
list of plain Java values
values
)

See the other overload of fromIterable(Iterable, String) for details, this one just uses a default origin description.

public static ConfigObject

Returns:

a new ConfigObject value
fromMap
(Map<String, ? extends Object>
map from keys to plain Java values
values
,
String
description to use in ConfigOrigin of created values
originDescription
)

See the fromAnyRef(Object, String) documentation for details.

public static ConfigObject

Returns:

a new ConfigObject
fromMap
(Map<String, ? extends Object>
map from keys to plain Java values
values
)

See the other overload fromMap(Map, String) for details, this one just uses a default origin description.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ConfigValueFactoryback to summary
private ConfigValueFactory()

Method Detail

fromAnyRefback to summary
public static ConfigValue fromAnyRef(Object object, String originDescription)

Creates a ConfigValue from a plain Java boxed value, which may be a Boolean, Number, String, Map, Iterable, or null. A Map must be a Map from String to more values that can be supplied to fromAnyRef(). An Iterable must iterate over more values that can be supplied to fromAnyRef(). A Map will become a ConfigObject and an Iterable will become a ConfigList. If the Iterable is not an ordered collection, results could be strange, since ConfigList is ordered.

In a Map passed to fromAnyRef(), the map's keys are plain keys, not path expressions. So 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 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.

If you pass in a ConfigValue to this function, it will be returned unmodified. (The originDescription will be ignored in this case.)

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

object to convert to ConfigValue

originDescription:String

name of origin file or brief description of what the value is

Returns:ConfigValue

a new value

fromAnyRefback to summary
public static ConfigValue fromAnyRef(Object object)

See the other overload fromAnyRef(Object, String) for details, this one just uses a default origin description.

Parameters
object:Object

a plain Java value

Returns:ConfigValue

a new ConfigValue

fromIterableback to summary
public static ConfigList fromIterable(Iterable<? extends Object> values, String originDescription)

See the fromAnyRef(Object, String) documentation for details. This is a typesafe wrapper that only works on java.lang.Iterable and returns ConfigList rather than ConfigValue.

Parameters
values:Iterable<? extends Object>

list of plain Java values

originDescription:String

description to use in ConfigOrigin of created values

Returns:ConfigList

a new ConfigList value

fromIterableback to summary
public static ConfigList fromIterable(Iterable<? extends Object> values)

See the other overload of fromIterable(Iterable, String) for details, this one just uses a default origin description.

Parameters
values:Iterable<? extends Object>

list of plain Java values

Returns:ConfigList

a new ConfigList

fromMapback to summary
public static ConfigObject fromMap(Map<String, ? extends Object> values, String originDescription)

See the fromAnyRef(Object, String) documentation for details. This is a typesafe wrapper that only works on java.util.Map and returns ConfigObject rather than ConfigValue.

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, the Map corresponds exactly to a single ConfigObject. The keys will not be parsed or modified, and the values are wrapped in ConfigValue. To get nested ConfigObject, 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:Map<String, ? extends Object>

map from keys to plain Java values

originDescription:String

description to use in ConfigOrigin of created values

Returns:ConfigObject

a new ConfigObject value

fromMapback to summary
public static ConfigObject fromMap(Map<String, ? extends Object> values)

See the other overload fromMap(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:Map<String, ? extends Object>

map from keys to plain Java values

Returns:ConfigObject

a new ConfigObject