All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.com.algolia.search.model.recommend.internal.RecommendationModelSerializer.kt Maven / Gradle / Ivy

Go to download

"Algolia is a powerful search-as-a-service solution, made easy to use with API clients, UI libraries, and pre-built integrations. Algolia API Client for Kotlin lets you easily use the Algolia Search REST API from your JVM project, such as Android or backend implementations."

There is a newer version: 3.12.2
Show newest version
package com.algolia.search.model.recommend.internal

import com.algolia.search.model.recommend.RecommendationModel
import kotlinx.serialization.KSerializer
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder

internal class RecommendationModelSerializer : KSerializer {

    override val descriptor: SerialDescriptor = String.serializer().descriptor

    override fun deserialize(decoder: Decoder): RecommendationModel {
        return when (val value = decoder.decodeString()) {
            RecommendationModel.RelatedProducts.model -> RecommendationModel.RelatedProducts
            RecommendationModel.BoughtTogether.model -> RecommendationModel.BoughtTogether
            else -> RecommendationModel(value)
        }
    }

    override fun serialize(encoder: Encoder, value: RecommendationModel) {
        encoder.encodeString(value.model)
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy