# TypeConverter

Artifact: [androidx.room:room-common](https://developer.android.com/jetpack/androidx/releases/room) [View Source](https://cs.android.com/search?q=file:androidx/room/TypeConverter.kt+class:androidx.room.TypeConverter) Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0)

*** ** * ** ***


```
@Target(allowedTargets = [AnnotationTarget.FUNCTION])
@Retention(value = AnnotationRetention.BINARY)
public annotation TypeConverter
```

<br />

*** ** * ** ***

Marks a method as a type converter. A class can have as many @TypeConverter methods as it needs.

Each converter method should receive 1 parameter and have non-void return type.

```
// example converter for java.util.Date
public class Converters {
    @TypeConverter
    public fun fromTimestamp(value: Long): Date {
        return value == null ? null : Date(value)
    }

    @TypeConverter
    public fun dateToTimestamp(date: Date): Long {
        if (date == null) {
            return null
        } else {
            return date.getTime()
        }
    }
}
```

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/room/TypeConverters` |   |