Skip to content

Instantly share code, notes, and snippets.

@ohefny
ohefny / Passing dynamic object through chains ( like RxJava ).md
Last active April 1, 2020 09:56
Passing dynamic object through chains ( like RxJava )

There are times when you're using chaining and you want to pass all the every chain result to the last chain without creating redundant types that will be only used once inside these chains
Note:: You can always do that by nesting chains which looks ugly

One Data Class with nullable members or default valued

This can also be achieved without copying using one data class with mutable members

@ohefny
ohefny / HybridResponseDeserializer.kt
Last active August 27, 2019 13:08
Deserializing JSON response which has a field that can be object or list using Gson deserializer in Kotlin.
import com.google.gson.*
import com.google.gson.reflect.TypeToken
import java.lang.reflect.Type
import java.lang.reflect.ParameterizedType
class HybridResponseDeserializer<T>(private val clazz: Class<T>, private val type: Type) : JsonDeserializer<HybridResponse<T>> {
override fun deserialize(
json: JsonElement?,
typeOfT: Type?,
context: JsonDeserializationContext?