Skip to content

Commit

Permalink
updated to specifically check for a parsed JsonNull, as that is more …
Browse files Browse the repository at this point in the history
…appropriate
  • Loading branch information
Rahkeen committed Jul 25, 2024
1 parent fe0ab0f commit 028c427
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonContentPolymorphicSerializer
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonNull
import kotlinx.serialization.json.jsonObject
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
Expand Down Expand Up @@ -36,8 +37,8 @@ sealed interface BaseResponse {

object BaseResponseSerializer : JsonContentPolymorphicSerializer<BaseResponse>(BaseResponse::class) {
override fun selectDeserializer(element: JsonElement) = when {
"id" in element.jsonObject -> BaseResponse.Item.serializer()
else -> BaseResponse.NullResponse.serializer()
element is JsonNull -> BaseResponse.NullResponse.serializer()
else -> BaseResponse.Item.serializer()
}
}

Expand Down

0 comments on commit 028c427

Please sign in to comment.