# InstantAsLongSerializer

Artifact: [androidx.appsearch:appsearch-builtin-types](https://developer.android.com/jetpack/androidx/releases/appsearch) [View Source](https://cs.android.com/search?q=file:androidx/appsearch/serializers/InstantAsLongSerializer.java+class:androidx.appsearch.serializers.InstantAsLongSerializer) Added in [1.2.0-alpha02](https://developer.android.com/jetpack/androidx/releases/appsearch#1.2.0-alpha02)

*** ** * ** ***


```
@RequiresApi(api = Build.VERSION_CODES.O)
public class InstantAsLongSerializer implements LongSerializer<Instant>
```

<br />

*** ** * ** ***

Serializes a `https://developer.android.com/reference/java/time/Instant.html` to and from a long. The Instant is serialized and deserialized from and to epoch milliseconds.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/appsearch/serializers/InstantAsLongSerializer#InstantAsLongSerializer()()` |

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/time/Instant.html` | `https://developer.android.com/reference/androidx/appsearch/serializers/InstantAsLongSerializer#deserialize(long)(long epochMilli)` Deserializes a long to an Instant. |
| `long` | `https://developer.android.com/reference/androidx/appsearch/serializers/InstantAsLongSerializer#serialize(java.time.Instant)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/time/Instant.html instant)` Serializes an Instant to a long. |

## Public constructors

### InstantAsLongSerializer

Added in 1.2.0-alpha02

```
public InstantAsLongSerializer()
```

## Public methods

### deserialize

Added in [1.2.0-alpha02](https://developer.android.com/jetpack/androidx/releases/appsearch#1.2.0-alpha02)

```
public @NonNull Instant deserialize(long epochMilli)
```

Deserializes a long to an Instant.

| Parameters |
|---|---|
| `long epochMilli` | The long to deserialize. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/time/Instant.html` | The Instant deserialized from the long. |

### serialize

Added in [1.2.0-alpha02](https://developer.android.com/jetpack/androidx/releases/appsearch#1.2.0-alpha02)

```
public long serialize(@NonNull Instant instant)
```

Serializes an Instant to a long.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/time/Instant.html instant` | The Instant to serialize. |

| Returns |
|---|---|
| `long` | The long serialized from the Instant. |