I have a class called Chacara with various properties including thumbList which is a List< String >
When saving it to ROOM I use a Type Converter:
class DbTypeConverter {
@TypeConverter
fun listToString(list: List<String>): String = Gson().toJson(list)
@TypeConverter
fun stringToList(string: String): List<String> {
return Gson().fromJson<List<String>>(string, object: TypeToken<List<String>>() {}.type)
}
}
When I fetch the entire object and access the the thumbList property it works as expected:
@Query("SELECT * FROM chacara WHERE id = :id LIMIT 1")
abstract fun getChacaraWithId(id: String): LiveData<Chacara>
However, when I try to fetch only the thumbList property, the result isn't converted:
@Query("SELECT thumbUrlList FROM chacara WHERE id = :id")
abstract fun getChacaraThumbList(id: String): LiveData<List<String>>
I've also added a log to the TypeConverter to make sure it wasn't being called.
TL;DR: ROOM not calling TypeConverter and not converting String back to List (SELECT 'column_name'), but works when requested the entire object (SELECT *)