-
-
Save sagar-viradiya/ce8f765f072e38ad92d84a4b34add0f4 to your computer and use it in GitHub Desktop.
DevFest India 2020 Day 3 - Type converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.room.TypeConverter | |
import com.devfest.india.bmsclone.data.local.database.entity.Movie | |
import com.google.gson.Gson | |
import com.google.gson.reflect.TypeToken | |
import java.lang.reflect.Type | |
object MovieTypeConverter { | |
@TypeConverter | |
@JvmStatic | |
fun fromList(value: List<Movie>) = Gson().toJson(value) | |
@TypeConverter | |
@JvmStatic | |
fun toList(value: String): List<Movie> { | |
val listType: Type = object : TypeToken<List<Movie>>() {}.type | |
return Gson().fromJson(value, listType) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment