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
-
Method Summary
Modifier and TypeMethodDescriptionInitializes anLDValue
as an array, from a sequence of this type.Initializes anLDValue
as an array, from a sequence of this type.abstract LDValue
Converts a value of the specified type to anLDValue
.objectFrom
(Map<String, T> map) Initializes anLDValue
as an object, from a map containing this type.abstract T
Converts anLDValue
to 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 anLDValue
to 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 anLDValue
as 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 anLDValue
as 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 anLDValue
as 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:
-