Class LDValue.Converter<T>
- Type Parameters:
T- the type to convert from/to
- Enclosing class:
- LDValue
LDValue and some other type.
Besides converting individual values, this provides factory methods like arrayOf(T...)
which transform a collection of the specified type to the corresponding LDValue
complex type.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionInitializes anLDValueas an array, from a sequence of this type.Initializes anLDValueas an array, from a sequence of this type.abstract LDValueConverts a value of the specified type to anLDValue.objectFrom(Map<String, T> map) Initializes anLDValueas an object, from a map containing this type.abstract TConverts anLDValueto a value of the specified type.
-
Constructor Details
-
Converter
public Converter()
-
-
Method Details
-
fromType
Converts a value of the specified type to anLDValue.This method should never throw an exception; if for some reason the value is invalid, it should return
LDValue.ofNull().- Parameters:
value- a value of this type- Returns:
- an
LDValue
-
toType
Converts anLDValueto a value of the specified type.This method should never throw an exception; if the conversion cannot be done, it should return the default value of the given type (zero for numbers, null for nullable types).
- Parameters:
value- anLDValue- Returns:
- a value of this type
-
arrayFrom
Initializes anLDValueas an array, from a sequence of this type.Values are copied, so subsequent changes to the source values do not affect the array.
Example:
List<Integer> listOfInts = ImmutableList.<Integer>builder().add(1).add(2).add(3).build(); LDValue arrayValue = LDValue.Convert.Integer.arrayFrom(listOfInts);- Parameters:
values- a sequence of elements of the specified type- Returns:
- a value representing a JSON array, or
LDValue.ofNull()if the parameter was null - See Also:
-
arrayOf
Initializes anLDValueas an array, from a sequence of this type.Values are copied, so subsequent changes to the source values do not affect the array.
Example:
LDValue arrayValue = LDValue.Convert.Integer.arrayOf(1, 2, 3);- Parameters:
values- a sequence of elements of the specified type- Returns:
- a value representing a JSON array, or
LDValue.ofNull()if the parameter was null - See Also:
-
objectFrom
Initializes anLDValueas an object, from a map containing this type.Values are copied, so subsequent changes to the source map do not affect the array.
Example:
Map<String, Integer> mapOfInts = ImmutableMap.<String, Integer>builder().put("a", 1).build(); LDValue objectValue = LDValue.Convert.Integer.objectFrom(mapOfInts);- Parameters:
map- a map with string keys and values of the specified type- Returns:
- a value representing a JSON object, or
LDValue.ofNull()if the parameter was null - See Also:
-