im saving an entity that looks like this
@Entity
data class Entity(
@PrimaryKey val id: Int,
val productPresentationList: List<Int>,
val supplierComparePriceList: List<SupplierComparePrice>
)
And, when I run the app i got this error message
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected an int but was BEGIN_OBJECT at line 1 column 3 path $[0]
at com.google.gson.Gson.fromJson(Gson.java:975)
at com.google.gson.Gson.fromJson(Gson.java:928)
at com.google.gson.Gson.fromJson(Gson.java:877)
at com.yopdev.wabi2b.db.Converters.restoreProductPresentation(Converters.kt:162)
at com.yopdev.wabi2b.db.dao.CartDao_Impl$6.call(CartDao_Impl.java:281)
at com.yopdev.wabi2b.db.dao.CartDao_Impl$6.call(CartDao_Impl.java:262)
at androidx.room.CoroutinesRoom$Companion$createFlow$1$1$1.invokeSuspend(CoroutinesRoom.kt:128)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:919)
So, after that i tried to use a converter like this
@TypeConverter
fun restoreProductPresentation(listOfString: String): List<Int> =
Gson().fromJson(listOfString, object : TypeToken<List<Int>>() {}.type)
@TypeConverter
fun saveProductPresentation(list: List<Int>): String =
Gson().toJson(list)
Unfortunately, that didn“t work either.
How can i achieve this ?