10

Given that I'm already using Moshi to convert the Retrofit response from JSON String to Objects, can I also configure the Room Database on Android to use Moshi for TypeConverter instead of manually typing up the TypeConverter functions and referencing Moshi?

Example of some code that I have been writing that I think seems redundant.

@TypeConverter
    fun fromJsonToPictures(value: String): List<PictureObject>? {

        val moshi = Moshi.Builder().build()
        val type = Types.newParameterizedType(List::class.java, PictureObject::class.java)
        val adapter = moshi.adapter<List<PictureObject>>(type)
        return adapter.fromJson(value)
    }
Brandon Lim
  • 271
  • 2
  • 12

0 Answers0