@@ -10,34 +10,53 @@ import com.algolia.search.serialize.Key_HighlightResult
1010import com.algolia.search.serialize.internal.JsonNonStrict
1111import com.algolia.search.serialize.internal.asJsonInput
1212import com.algolia.search.serialize.internal.jsonObjectOrNull
13- import kotlinx.serialization.DeserializationStrategy
14- import kotlinx.serialization.ExperimentalSerializationApi
13+ import kotlinx.serialization.KSerializer
1514import kotlinx.serialization.SerialName
1615import kotlinx.serialization.Serializable
17- import kotlinx.serialization.Serializer
16+ import kotlinx.serialization.descriptors.SerialDescriptor
1817import kotlinx.serialization.encoding.Decoder
18+ import kotlinx.serialization.encoding.Encoder
1919import kotlinx.serialization.json.JsonObject
2020import kotlinx.serialization.json.jsonObject
2121
2222@Serializable
2323public data class ResponseSearchRules (
24+
2425 /* *
2526 * A list of [Hit].
2627 */
2728 @SerialName(KeyHits ) val hits : List <Hit >,
29+
30+ /* *
31+ * Number of hits or null.
32+ */
33+ @SerialName(KeyNbHits ) val nbHitsOrNull : Int? = null ,
34+
35+ /* *
36+ * Returned page number or null.
37+ */
38+ @SerialName(KeyPage ) val pageOrNull : Int? = null ,
39+
40+ /* *
41+ * Total number of pages or null.
42+ */
43+ @SerialName(KeyNbPages ) val nbPagesOrNull : Int? = null
44+ ) {
45+
2846 /* *
2947 * Number of hits.
3048 */
31- @SerialName(KeyNbHits ) val nbHits : Int ,
49+ val nbHits: Int get() = requireNotNull(nbHitsOrNull)
50+
3251 /* *
3352 * Returned page number.
3453 */
35- @SerialName(KeyPage ) val page : Int ,
54+ val page: Int get() = requireNotNull(pageOrNull)
55+
3656 /* *
3757 * Total number of pages.
3858 */
39- @SerialName(KeyNbPages ) val nbPages : Int
40- ) {
59+ val nbPages: Int get() = requireNotNull(nbPagesOrNull)
4160
4261 @Serializable(Hit .Companion ::class )
4362 public data class Hit (
@@ -48,17 +67,20 @@ public data class ResponseSearchRules(
4867 public val highlightResult: JsonObject
4968 get() = highlightResultOrNull!!
5069
51- @OptIn( ExperimentalSerializationApi :: class )
52- @Serializer( Hit :: class )
53- public companion object : DeserializationStrategy < Hit > {
70+ public companion object : KSerializer < Hit > {
71+
72+ override val descriptor : SerialDescriptor = Rule .serializer().descriptor
5473
5574 override fun deserialize (decoder : Decoder ): Hit {
5675 val json = decoder.asJsonInput().jsonObject
5776 val rule = JsonNonStrict .decodeFromJsonElement(Rule .serializer(), json)
5877 val highlightResult = json[Key_HighlightResult ]?.jsonObjectOrNull
59-
6078 return Hit (rule, highlightResult)
6179 }
80+
81+ override fun serialize (encoder : Encoder , value : Hit ) {
82+ throw UnsupportedOperationException (" ResponseSearchRules.Hit serialization is not an expected operation" )
83+ }
6284 }
6385 }
6486}
0 commit comments