
com.pubnub.internal.utils.UnwrapSingleField.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pubnub-kotlin-impl Show documentation
Show all versions of pubnub-kotlin-impl Show documentation
PubNub is a cross-platform client-to-client (1:1 and 1:many) push service in the cloud, capable of broadcasting real-time messages to millions of web and mobile clients simultaneously, in less than a quarter second!
package com.pubnub.internal.utils
import com.google.gson.JsonDeserializationContext
import com.google.gson.JsonDeserializer
import com.google.gson.JsonElement
import java.lang.reflect.Type
internal class UnwrapSingleField : JsonDeserializer {
override fun deserialize(
json: JsonElement,
typeOfT: Type,
context: JsonDeserializationContext,
): T {
val jsonObject = json.asJsonObject
if (jsonObject.keySet().size != 1) {
error("Couldn't unwrap field for object containing more than 1 field. Actual number of fields: ${jsonObject.keySet().size}")
}
val element = jsonObject[jsonObject.keySet().first()]
return context.deserialize(element, typeOfT)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy