deserialize

Deserialize the provided data into an object of type T using the deserializer function defined in the SSESessionWithDeserialization interface.

Report a problem

Return

The deserialized object of type T, or null if deserialization is not successful.

Example of usage:

client.sse({
    url("http://localhost:8080/serverSentEvents")
}, deserialize = {
    typeInfo, jsonString ->
    val serializer = Json.serializersModule.serializer(typeInfo.kotlinType!!)
    Json.decodeFromString(serializer, jsonString)!!
}) { // `this` is `ClientSSESessionWithDeserialization`
    incoming.collect { event: TypedServerSentEvent<String> ->
        when (event.event) {
            "customer" -> {
                val customer: Customer? = deserialize<Customer>(event.data)
            }
            "product" -> {
                val product: Product? = deserialize<Product>(event.data)
            }
        }
    }
}

Parameters

data

The string data to deserialize.


Deserialize the provided event data into an object of type T using the deserializer function defined in the SSESessionWithDeserialization interface.

Report a problem

Return

The deserialized object of type T, or null if deserialization is not successful.

Example of usage:

client.sse({
    url("http://localhost:8080/serverSentEvents")
}, deserialize = {
    typeInfo, jsonString ->
    val serializer = Json.serializersModule.serializer(typeInfo.kotlinType!!)
    Json.decodeFromString(serializer, jsonString)!!
}) { // `this` is `ClientSSESessionWithDeserialization`
    incoming.collect { event: TypedServerSentEvent<String> ->
        when (event.event) {
            "customer" -> {
                val customer: Customer? = deserialize<Customer>(event.data)
            }
            "product" -> {
                val product: Product? = deserialize<Product>(event.data)
            }
        }
    }
}

Parameters

event

The Server-sent event containing data to deserialize.