Skip to content

Instantly share code, notes, and snippets.

@vickyturtle
vickyturtle / Converter.kt
Last active November 14, 2023 20:18
Custom Retrofit converter for wrapped responses
class CustomConverterFactory(gson: Gson) : Converter.Factory() {
private val gsonConverterFactory: GsonConverterFactory = GsonConverterFactory.create(gson)
override fun responseBodyConverter(type: Type, annotations: Array<Annotation>, retrofit: Retrofit): Converter<ResponseBody, *>? {
val wrappedType = object : ParameterizedType {
override fun getActualTypeArguments(): Array<Type> = arrayOf(type)
override fun getOwnerType(): Type? = null
override fun getRawType(): Type = Data::class.java
}