Davide Giuseppe Farella
03/16/2023, 9:36 PM[
{ // MovieRating.kt
"rating": 7
"movie": { // Movie.kt
"title": ...,
...
},
{ // ShowRating.kt
"rating": 8
"show": { // Show.kt
"title": ...,
...
}
]
For Movie
and Show
I've set the discriminator as:
@SerialName("movie")
data class Movie(...): Parent
Now, how to properly set a discriminator for MovieRating
and ShowRating
, based on the inner field "movie"
/ "show"
?ephemient
03/16/2023, 9:52 PM@Serializable
data class RatingContainer(
val rating: Int,
movie: MovieRating? = null,
show: ShowRating? = null,
)
and then map that to the structure you want, possibly wrapped up with https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/serializers.md#composite-serializer-via-surrogateDavide Giuseppe Farella
03/16/2023, 10:08 PM