How to use Moshi for Room TypeConverter with Nested Object

43 Views Asked by At

need some help, here are the classes I have

interface Person {
   val age: Age,
   val children: List<Person>,   // this part is causing the issue
}
interface Age {
   val number: Long
}

@JsonClass(generateAdapter = true)
class PersonImpl(
   override val age: Age,
) : Person

@JsonClass(generateAdapter = true)
class AgeImpl() : Age

I also created my own adapter to resolve interface issues, but still have following issue

so I have tried various way to write moshi for it, but with all kinds of errors. so I was finally made it work for a Person object with no children. but when there is children, it says no jsonAdapter for interface Age.

Need some help! Thanks in advance!

0

There are 0 best solutions below