# DocumentClassFactory

Artifact: [androidx.appsearch:appsearch](https://developer.android.com/jetpack/androidx/releases/appsearch) [View Source](https://cs.android.com/search?q=file:androidx/appsearch/app/DocumentClassFactory.java+class:androidx.appsearch.app.DocumentClassFactory) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

*** ** * ** ***

<br />

```
public interface DocumentClassFactory<T>
```

<br />

*** ** * ** ***

An interface for factories which can convert between instances of classes annotated with \\@`https://developer.android.com/reference/androidx/appsearch/annotation/Document` and instances of `https://developer.android.com/reference/androidx/appsearch/app/GenericDocument`.

| Parameters |
|---|---|
| `<T>` | The document class type this factory converts to and from `https://developer.android.com/reference/androidx/appsearch/app/GenericDocument`. |

## Summary

| ### Public methods |
|---|---|
| `abstract @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html T` | `@https://developer.android.com/reference/androidx/appsearch/app/ExperimentalAppSearchApi https://developer.android.com/reference/androidx/appsearch/app/DocumentClassFactory#fromGenericDocument(androidx.appsearch.app.GenericDocument,androidx.appsearch.app.DocumentClassMappingContext)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/appsearch/app/GenericDocument genericDoc, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/appsearch/app/DocumentClassMappingContext documentClassMappingContext )` Converts a `https://developer.android.com/reference/androidx/appsearch/app/GenericDocument` into an instance of the document class. |
| `abstract @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/java/lang/Class.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?>>` | `https://developer.android.com/reference/androidx/appsearch/app/DocumentClassFactory#getDependencyDocumentClasses()()` Returns document classes that this document class depends on. |
| `abstract @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/appsearch/app/AppSearchSchema` | `https://developer.android.com/reference/androidx/appsearch/app/DocumentClassFactory#getSchema()()` Returns the schema for this document class. |
| `abstract @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/appsearch/app/DocumentClassFactory#getSchemaName()()` Returns the name of this schema type, e.g. |
| `abstract @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/appsearch/app/GenericDocument` | `https://developer.android.com/reference/androidx/appsearch/app/DocumentClassFactory#toGenericDocument(T)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html T document)` Converts an instance of the class annotated with \\@`https://developer.android.com/reference/androidx/appsearch/annotation/Document` into a `https://developer.android.com/reference/androidx/appsearch/app/GenericDocument`. |

## Public methods

### fromGenericDocument

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

```
@ExperimentalAppSearchApi
abstract @NonNull T fromGenericDocument(
    @NonNull GenericDocument genericDoc,
    @NonNull DocumentClassMappingContext documentClassMappingContext
)
```

Converts a `https://developer.android.com/reference/androidx/appsearch/app/GenericDocument` into an instance of the document class. For nested document properties, this method should pass `documentClassMappingContext` down to the nested calls of `https://developer.android.com/reference/androidx/appsearch/app/GenericDocument#toDocumentClass(java.lang.Class<T>,androidx.appsearch.app.DocumentClassMappingContext)`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/appsearch/app/GenericDocument genericDoc` | The document to convert. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/appsearch/app/DocumentClassMappingContext documentClassMappingContext` | The context object that holds mapping information for document classes and their parent types. This context typically comes from `https://developer.android.com/reference/androidx/appsearch/app/SearchResult#getDocument(java.lang.Class<T>,java.util.Map<java.lang.String,java.util.List<java.lang.String>>)`. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/appsearch/exceptions/AppSearchException` |   |

### getDependencyDocumentClasses

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

```
abstract @NonNull List<Class<@NonNull ?>> getDependencyDocumentClasses()
```

Returns document classes that this document class depends on. This is useful so clients are not required to explicitly set all dependencies.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/appsearch/exceptions/AppSearchException` |   |

### getSchema

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

```
abstract @NonNull AppSearchSchema getSchema()
```

Returns the schema for this document class.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/appsearch/exceptions/AppSearchException` |   |

### getSchemaName

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

```
abstract @NonNull String getSchemaName()
```

Returns the name of this schema type, e.g. `Email`.

This is the name used in queries for type restricts.

### toGenericDocument

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

```
abstract @NonNull GenericDocument toGenericDocument(@NonNull T document)
```

Converts an instance of the class annotated with \\@`https://developer.android.com/reference/androidx/appsearch/annotation/Document` into a `https://developer.android.com/reference/androidx/appsearch/app/GenericDocument`.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/appsearch/exceptions/AppSearchException` |   |