I'm trying to use PolymorphicJsonAdapterFactory in order to obtain different types, but am always getting odd exception:
Missing label for test_type
My entity:
@JsonClass(generateAdapter = true)
data class TestResult(
@Json(name = "test_type") val testType: TestType,
...
@Json(name = "session") val session: Session,
...
)
Here is my moshi factory:
val moshiFactory = Moshi.Builder()
.add(
PolymorphicJsonAdapterFactory.of(Session::class.java, "test_type")
.withSubtype(FirstSession::class.java, "first")
.withSubtype(SecondSession::class.java, "second")
)
.build()
Structure of json response:
{
response: [
test_type: "first",
...
]
}