0

I have the following data structure that I want to deserialize:

@Serializable
data class SearchResponse(val results: List<SearchResultContainer>) {

    @Serializable
    data class SearchResultContainer(
        val type: ResultType,
        val result: SearchResult
    )

    @Serializable
    enum class ResultType {
        SERIES, SERIES_CRUMB, EPISODE, CHANNEL
    }

    @Serializable
    sealed interface SearchResult

    @Serializable
    data class SeriesSearchResult(
        val id: String,
        val name: String,
        val description: String,
        val image: String
    ) : SearchResult

    // ...

I want to deserialize concrete SearchResult based on enum - ResultType.

Do I need to register custom serializer for this?

shaktiman_droid
  • 2,368
  • 1
  • 17
  • 32
pixel
  • 24,905
  • 36
  • 149
  • 251
  • Does this answer your question? [Decoding JSON to a class based on the value of another JSON key](https://stackoverflow.com/questions/74489345/decoding-json-to-a-class-based-on-the-value-of-another-json-key) – aSemy Nov 29 '22 at 02:07

0 Answers0