Value

The Value class is the untyped representation of any SurrealDB value. It provides methods to check the underlying type and extract the value as a native Java type or SDK class. You can also convert a Value to a Java POJO using .get(Class<T>).

Source: surrealdb.java

Type Checking Methods

Each method returns true when the Value holds the corresponding SurrealDB type.

MethodReturns true when
isNone()Value is NONE
isNull()Value is NULL
isBoolean()Value is a boolean
isDouble()Value is a float/double
isLong()Value is an integer/long
isBigDecimal()Value is a decimal
isString()Value is a string
isUuid()Value is a UUID
isArray()Value is an array
isObject()Value is an object
isGeometry()Value is a geometry
isDateTime()Value is a datetime
isDuration()Value is a duration
isBytes()Value is binary data
isRecordId()Value is a record ID
isFile()Value is a file reference
isRange()Value is a range
isTable()Value is a table name

Getter Methods

Each getter extracts the underlying value. Call the corresponding type check method first to avoid unexpected results.

MethodReturn Type
getBoolean()boolean
getDouble()double
getLong()long
getBigDecimal()BigDecimal
getString()String
getUuid()UUID
getArray()Array
getObject()Object
getGeometry()Geometry
getDateTime()ZonedDateTime
getDuration()Duration
getBytes()byte[]
getRecordId()RecordId
getFile()FileRef
getRangeStart()Optional<Value>
getRangeEnd()Optional<Value>
getTable()String

POJO Conversion

.get(type)

Converts the value to a Java POJO. The target class must have a public no-argument constructor. Fields are matched by name between the SurrealDB object and the Java class.

Method Syntax

<T> T get(Class<T> type)
ParameterTypeDescription
type Class<T>The target class to deserialize into.

Returns: T

Example

public class Person {
public RecordId id;
public String name;
public long age;
}

Response response = db.query("SELECT * FROM person:tobie");
Value value = response.take(0);
Person person = value.get(Person.class);

Array

The Array class represents a SurrealDB array value. It implements Iterable<Value> and provides both untyped and typed iteration.

Methods

.get(idx)

Returns the value at the specified index.

Method Syntax

array.get(idx)
ParameterTypeDescription
idx intThe zero-based index of the element.

Returns: Value

.len()

Returns the number of elements in the array.

Method Syntax

array.len()

Returns: int

.iterator()

Returns an iterator over the array elements as Value instances.

Method Syntax

array.iterator()

Returns: Iterator<Value>

.iterator(clazz)

Returns a typed iterator that deserializes each element into the specified class.

Method Syntax

array.iterator(clazz)
ParameterTypeDescription
clazz Class<T>The class to deserialize each element into.

Returns: Iterator<T>

.synchronizedIterator()

Returns a thread-safe iterator over the array elements.

Method Syntax

array.synchronizedIterator()

Returns: Iterator<Value>

.synchronizedIterator(clazz)

Returns a thread-safe typed iterator that deserializes each element into the specified class.

Method Syntax

array.synchronizedIterator(clazz)
ParameterTypeDescription
clazz Class<T>The class to deserialize each element into.

Returns: Iterator<T>

Example

Response response = db.query("SELECT * FROM person");
Value result = response.take(0);
Array array = result.getArray();

for (Value item : array) {
String name = item.getObject().get("name").getString();
}

Iterator<Person> people = array.iterator(Person.class);
while (people.hasNext()) {
Person person = people.next();
}

Object

The Object class represents a SurrealDB object value. It implements Iterable<Entry> and provides key-based access to its fields.

Methods

.get(key)

Returns the value associated with the specified key.

Method Syntax

object.get(key)
ParameterTypeDescription
key StringThe field name to look up.

Returns: Value

.len()

Returns the number of key-value pairs in the object.

Method Syntax

object.len()

Returns: int

.iterator()

Returns an iterator over the object's key-value pairs as Entry instances.

Method Syntax

object.iterator()

Returns: Iterator<Entry>

.synchronizedIterator()

Returns a thread-safe iterator over the object's key-value pairs.

Method Syntax

object.synchronizedIterator()

Returns: Iterator<Entry>

Example

Response response = db.query("SELECT * FROM person:tobie");
Value result = response.take(0);
Object obj = result.getObject();

Value name = obj.get("name");
int fieldCount = obj.len();

for (Entry entry : obj) {
String key = entry.getKey();
Value value = entry.getValue();
}

Entry

The Entry class represents a key-value pair in a SurrealDB object.

Methods

.getKey()

Returns the field name of this entry.

Method Syntax

entry.getKey()

Returns: String

.getValue()

Returns the value of this entry.

Method Syntax

entry.getValue()

Returns: Value

See Also