commonMain.com.algolia.search.model.recommend.internal.RecommendationModelSerializer.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of algoliasearch-client-kotlin-jvm Show documentation
Show all versions of algoliasearch-client-kotlin-jvm Show documentation
"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."
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