• Start

API Reference

/

Data types

Value

The Value class represents any SurrealDB value and provides type checking and conversion methods.

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)`.

Source: surrealdb.java

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

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

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)

Parameter

Type

Description

typeClass<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);

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

Returns the value at the specified index.

Method Syntax
array.get(idx)

Parameter

Type

Description

idxint

The zero-based index of the element.

Returns: Value

Returns the number of elements in the array.

Method Syntax
array.len()

Returns: int

Returns an iterator over the array elements as Value instances.

Method Syntax
array.iterator()

**Returns:** `Iterator`

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

Method Syntax
array.iterator(clazz)

Parameter

Type

Description

clazzClass<T>

The class to deserialize each element into.

**Returns:** `Iterator`

Returns a thread-safe iterator over the array elements.

Method Syntax
array.synchronizedIterator()

**Returns:** `Iterator`

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

Method Syntax
array.synchronizedIterator(clazz)

Parameter

Type

Description

clazzClass<T>

The class to deserialize each element into.

**Returns:** `Iterator`

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();
}

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

Returns the value associated with the specified key.

Method Syntax
object.get(key)

Parameter

Type

Description

keyString

The field name to look up.

Returns: Value

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

Method Syntax
object.len()

Returns: int

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

Method Syntax
object.iterator()

**Returns:** `Iterator`

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

Method Syntax
object.synchronizedIterator()

**Returns:** `Iterator`

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.

.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

Was this page helpful?