public abstract class Value extends Expr
Value
represents query responses from FaunaDB.
Instances of Value
should be treated as opaque vales until converted to a native type.
Available conversion methods are:
to(Class)
to(Codec)
get(Field)
getOptional(Field)
collect(Field)
asCollectionOf(Class)
asMapOf(Class)
Examples:
Using the traversal API:
Value result = client.query(getUserQuery).get();
String name = result
.at("data", "name")
.to(String.class)
.get();
Using a field extractor:
Field<String> name = Field.at("data", "name").to(String.class);
Value result = client.query(getUserQuery).get();
String name = result.get(name);
Field
,
Codec
Modifier and Type | Class and Description |
---|---|
static class |
Value.ArrayV
Represents an array value in the FaunaDB query language.
|
static class |
Value.BooleanV
Represents a boolean value in the FaunaDB query language.
|
static class |
Value.BytesV
Represents a blob value in the FaunaDB query language.
|
static class |
Value.DateV
Represents a date value in the FaunaDB query language.
|
static class |
Value.DoubleV
Represents a double value in the FaunaDB query language.
|
static class |
Value.LongV
Represents a long value in the FaunaDB query language.
|
static class |
Value.Native
Builtin reference types.
|
static class |
Value.NullV
Represents a null value in the FaunaDB query language.
|
static class |
Value.ObjectV
Represents an Object value in the FaunaDB query language.
|
static class |
Value.QueryV
Represents a query value in the FaunaDB query language.
|
static class |
Value.RefID
The
Value.RefV internal ID representation. |
static class |
Value.RefV
A FaunaDB reference type.
|
static class |
Value.SetRefV
A FaunaDB set literal.
|
static class |
Value.StringV
Represents a string value in the FaunaDB query language.
|
static class |
Value.TimeV
Represents a timestamp value in the FaunaDB query language.
|
Modifier and Type | Method and Description |
---|---|
<T> Result<java.util.Collection<T>> |
asCollectionOf(java.lang.Class<T> elementType)
Attempts to convert the value to a
Collection . |
<T> Result<java.util.Map<java.lang.String,T>> |
asMapOf(java.lang.Class<T> valueType)
Attempts to convert the value to a
Map . |
Value |
at(int... indexes)
Assuming the underlying value is a collection, it traverses to a desired path.
|
Value |
at(java.lang.String... keys)
Assuming the underlying value is a key/value map, it traverses to a desired path.
|
<T> java.util.Collection<T> |
collect(java.lang.Class<T> elementType)
Attempts to convert the value to a
Collection . |
<T> java.util.List<T> |
collect(Field<T> field)
Assuming the underlying value is a collection, it collects the
Field provided
for all elements in the collection. |
static <T> Result<Value> |
from(T obj)
|
<T> T |
get(java.lang.Class<T> clazz)
Attempts to decode the value using the reflection
Decoder . |
<T> T |
get(Field<T> field)
Extract a
Field from the value. |
java.util.Optional<Value> |
getOptional()
Converts this into an
Optional . |
<T> java.util.Optional<T> |
getOptional(Field<T> field)
Safely attempts to extract a
Field from this value. |
Value |
orNull()
Returns this value, or returns null if no value is present.
|
<T> Result<T> |
to(java.lang.Class<T> clazz)
Attempts to decode the value using the reflection
Decoder . |
<T> Result<T> |
to(Codec<T> codec)
Attempts to convert the value using the
Codec passed. |
<T> java.util.Map<java.lang.String,T> |
toMap(java.lang.Class<T> valueType)
Attempts to convert the value to a
Map . |
public final <T> Result<T> to(Codec<T> codec)
Codec
passed.public final <T> Result<T> to(java.lang.Class<T> clazz)
Decoder
.public static <T> Result<Value> from(T obj)
T
- the type to convert fromobj
- the object instance to encodeResult
of the conversionpublic final <T> Result<java.util.Map<java.lang.String,T>> asMapOf(java.lang.Class<T> valueType)
Map
.public final <T> java.util.Map<java.lang.String,T> toMap(java.lang.Class<T> valueType)
Map
.public final <T> Result<java.util.Collection<T>> asCollectionOf(java.lang.Class<T> elementType)
Collection
.public final <T> java.util.Collection<T> collect(java.lang.Class<T> elementType)
Collection
.public final <T> T get(java.lang.Class<T> clazz)
Decoder
.T
- the type to convert toclazz
- a class type to convertDecoder
public final <T> java.util.Optional<T> getOptional(Field<T> field)
Field
from this value.public java.util.Optional<Value> getOptional()
Optional
.Optional
containing this value, if present.public final Value orNull()
public final <T> java.util.List<T> collect(Field<T> field)
Field
provided
for all elements in the collection.
For example:
Field<String> userName = Field.at("name").to(String.class);
Value result = client.query(getAllUsersQuery).get();
List<String> userNames = result.at("data").collect(userName);
public final Value at(java.lang.String... keys)
For example:
Value result = client.query(getUser).get();
Value zipCode = result.at("data", "address", "zipCode");
keys
- the object keys to traverseValue
under the path providedpublic final Value at(int... indexes)
For example:
Value result = client.query(getAllUsers).get();
Value firstUser = result.at("data").at(0);
indexes
- the collection indexes to traverseValue
under the path provided