commonMain.com.algolia.client.model.search.SearchResult.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 Show documentation
Show all versions of algoliasearch-client-kotlin 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."
/** Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. */
package com.algolia.client.model.search
import com.algolia.client.exception.AlgoliaClientException
import com.algolia.client.extensions.internal.*
import kotlinx.serialization.*
import kotlinx.serialization.builtins.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*
import kotlinx.serialization.json.*
/**
* SearchResult
*
* Implementations:
* - [SearchForFacetValuesResponse]
* - [SearchResponse]
*/
@Serializable(SearchResultSerializer::class)
public sealed interface SearchResult {
public companion object {
}
}
internal class SearchResultSerializer : KSerializer {
override val descriptor: SerialDescriptor = buildClassSerialDescriptor("SearchResult")
override fun serialize(encoder: Encoder, value: SearchResult) {
when (value) {
is SearchForFacetValuesResponse -> SearchForFacetValuesResponse.serializer().serialize(encoder, value)
is SearchResponse -> SearchResponse.serializer().serialize(encoder, value)
}
}
override fun deserialize(decoder: Decoder): SearchResult {
val codec = decoder.asJsonDecoder()
val tree = codec.decodeJsonElement()
// deserialize SearchForFacetValuesResponse
if (tree is JsonObject && tree.containsKey("facetHits")) {
try {
return codec.json.decodeFromJsonElement(SearchForFacetValuesResponse.serializer(), tree)
} catch (e: Exception) {
// deserialization failed, continue
println("Failed to deserialize SearchForFacetValuesResponse (error: ${e.message})")
}
}
// deserialize SearchResponse
if (tree is JsonObject) {
try {
return codec.json.decodeFromJsonElement(SearchResponse.serializer(), tree)
} catch (e: Exception) {
// deserialization failed, continue
println("Failed to deserialize SearchResponse (error: ${e.message})")
}
}
throw AlgoliaClientException("Failed to deserialize json element: $tree")
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy