TypeConverters


@Target(allowedTargets = [AnnotationTarget.FUNCTIONAnnotationTarget.VALUE_PARAMETERAnnotationTarget.FIELDAnnotationTarget.CLASS])
@Retention(value = AnnotationRetention.BINARY)
public annotation TypeConverters


Specifies additional type converters that Room can use. The TypeConverter functions are added to the scope of the element so if you put it on a class / interface, all functions / properties in that class will be able to use the converters.

@TypeConverters can only be used to convert columns / properties, hence cannot be used by a function to convert a row return value such as DAO function that query rows, for such cases use DaoReturnTypeConverters.

  • If you put it on a Database, all DAOs and entities in that database will be able to use it.

  • If you put it on a Dao, all functions in the DAO will be able to use it.

  • If you put it on an Entity, all properties of the entity will be able to use it.

  • If you put it on a data object class, all properties of the data class will be able to use it.

  • If you put it on an Entity property, only that property will be able to use it.

  • If you put it on a Dao function, all parameters of the function will be able to use it.

  • If you put it on a Dao function parameter, just that property will be able to use it.

Summary

Public constructors

TypeConverters(
    @NonNull KClass<@NonNull ?>... value,
    @NonNull BuiltInTypeConverters builtInTypeConverters
)

Public methods

final @NonNull BuiltInTypeConverters

Configure whether Room can use various built in converters for common types.

final @NonNull KClass[]

The list of type converter classes.

Public constructors

TypeConverters

Added in 3.0.0-alpha01
public TypeConverters(
    @NonNull KClass<@NonNull ?>... value,
    @NonNull BuiltInTypeConverters builtInTypeConverters
)

Public methods

getBuiltInTypeConverters

public final @NonNull BuiltInTypeConverters getBuiltInTypeConverters()

Configure whether Room can use various built in converters for common types. See BuiltInTypeConverters for details.

getValue

public final @NonNull KClass[] getValue()

The list of type converter classes. If converter class is not an object Room will create an instance of these classes.

Returns
@NonNull KClass[]

The list of classes that contains the converter functions.