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

**Source:** [surrealdb.java](https://github.com/surrealdb/surrealdb.java)

---

## Type checking methods {#type-checking}

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

| Method | Returns `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 {#getters}

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

| Method | Return Type |
|---|---|
| `getBoolean()` | `boolean` |
| `getDouble()` | `double` |
| `getLong()` | `long` |
| `getBigDecimal()` | `BigDecimal` |
| `getString()` | `String` |
| `getUuid()` | `UUID` |
| `getArray()` | [`Array`](#array) |
| `getObject()` | [`Object`](#object) |
| `getGeometry()` | [`Geometry`](/docs/reference/java/api/values/geometry.md) |
| `getDateTime()` | `ZonedDateTime` |
| `getDuration()` | `Duration` |
| `getBytes()` | `byte[]` |
| `getRecordId()` | [`RecordId`](/docs/reference/java/api/values/record-id.md) |
| `getFile()` | [`FileRef`](/docs/reference/java/api/values/file-ref.md) |
| `getRangeStart()` | `Optional<Value>` |
| `getRangeEnd()` | `Optional<Value>` |
| `getTable()` | `String` |

---

## POJO conversion {#pojo-conversion}

### `.get(type)` {#get}

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.

```java title="Method Syntax"
<T> T get(Class<T> type)
```

<table>
    <thead>
        <tr>
            <th>Parameter</th>
            <th>Type</th>
            <th>Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><code>type</code> _(required)_</td>
            <td><code>Class&lt;T&gt;</code></td>
            <td>The target class to deserialise into.</td>
        </tr>
    </tbody>
</table>

**Returns:** `T`

```java title="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` {#array}

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

### Methods

#### `.get(idx)` {#array-get}

Returns the value at the specified index.

```java title="Method Syntax"
array.get(idx)
```

<table>
    <thead>
        <tr>
            <th>Parameter</th>
            <th>Type</th>
            <th>Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><code>idx</code> _(required)_</td>
            <td><code>int</code></td>
            <td>The zero-based index of the element.</td>
        </tr>
    </tbody>
</table>

**Returns:** `Value`

#### `.len()` {#array-len}

Returns the number of elements in the array.

```java title="Method Syntax"
array.len()
```

**Returns:** `int`

#### `.iterator()` {#array-iterator}

Returns an iterator over the array elements as `Value` instances.

```java title="Method Syntax"
array.iterator()
```

**Returns:** `Iterator<Value>`

#### `.iterator(clazz)` {#array-typed-iterator}

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

```java title="Method Syntax"
array.iterator(clazz)
```

<table>
    <thead>
        <tr>
            <th>Parameter</th>
            <th>Type</th>
            <th>Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><code>clazz</code> _(required)_</td>
            <td><code>Class&lt;T&gt;</code></td>
            <td>The class to deserialise each element into.</td>
        </tr>
    </tbody>
</table>

**Returns:** `Iterator<T>`

#### `.synchronizedIterator()` {#array-sync-iterator}

Returns a thread-safe iterator over the array elements.

```java title="Method Syntax"
array.synchronizedIterator()
```

**Returns:** `Iterator<Value>`

#### `.synchronizedIterator(clazz)` {#array-sync-typed-iterator}

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

```java title="Method Syntax"
array.synchronizedIterator(clazz)
```

<table>
    <thead>
        <tr>
            <th>Parameter</th>
            <th>Type</th>
            <th>Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><code>clazz</code> _(required)_</td>
            <td><code>Class&lt;T&gt;</code></td>
            <td>The class to deserialise each element into.</td>
        </tr>
    </tbody>
</table>

**Returns:** `Iterator<T>`

```java title="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` {#object}

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

### Methods

#### `.get(key)` {#object-get}

Returns the value associated with the specified key.

```java title="Method Syntax"
object.get(key)
```

<table>
    <thead>
        <tr>
            <th>Parameter</th>
            <th>Type</th>
            <th>Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><code>key</code> _(required)_</td>
            <td><code>String</code></td>
            <td>The field name to look up.</td>
        </tr>
    </tbody>
</table>

**Returns:** `Value`

#### `.len()` {#object-len}

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

```java title="Method Syntax"
object.len()
```

**Returns:** `int`

#### `.iterator()` {#object-iterator}

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

```java title="Method Syntax"
object.iterator()
```

**Returns:** `Iterator<Entry>`

#### `.synchronizedIterator()` {#object-sync-iterator}

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

```java title="Method Syntax"
object.synchronizedIterator()
```

**Returns:** `Iterator<Entry>`

```java title="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` {#entry}

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

### Methods

#### `.getKey()` {#entry-key}

Returns the field name of this entry.

```java title="Method Syntax"
entry.getKey()
```

**Returns:** `String`

#### `.getValue()` {#entry-value}

Returns the value of this entry.

```java title="Method Syntax"
entry.getValue()
```

**Returns:** `Value`

---

## See also

- [Value types](/docs/reference/java/concepts/value-types.md) - Type mapping overview
- [RecordId](/docs/reference/java/api/values/record-id.md) - Record identifiers
- [SurrealQL data model](/docs/reference/query-language/language-primitives/data-types.md) - SurrealDB data types and structures
