https://kotlinlang.org logo
Title
r

Reprator

05/21/2023, 3:43 PM
Hi Mates, Can anyone help me, how can i write, "Ktor-client Converter for wrapped responses" in a generic class internally like (https://medium.com/hackernoon/retrofit-converter-for-wrapped-responses-8919298a549c) Example: Suppose an api gives following response, @Serializable @SerialName("DataResponseContainer") data class DataResponseContainer<out T>(val data: T?, val statusCode: Int?, val message: String?) { "data" : {...} "status_code" : 0 "error_message" : null } for which we write the client as follows, httpClient.get("splash").body<DataResponseContainer<SplashEntity>>() now, i need only, "data" object, so i want to write it like, httpClient.get("splash").body<SplashEntity>()
a

Aleksei Tirman [JB]

05/22/2023, 6:51 AM
Unfortunately, the declared received type must match the type of a deserialized object; otherwise the
NoTransformationFoundException
will be thrown because of the
if (result != null && !result._instanceOf_(info.type))
check in the
bodyNullable
method.
r

Reprator

05/22/2023, 7:18 AM
@Aleksei Tirman [JB] is there any way to do this, like writing custom plug-in. I had written in this way but getting parsing exceptions
a

Aleksei Tirman [JB]

05/22/2023, 9:09 AM
Unfortunately, I don't see a way to solve your problem.
j

Júlio Santos

05/23/2023, 2:49 AM
Hi @Reprator, what's up? I think understand your question, the my job I use jsonToObject
r

Reprator

05/23/2023, 5:22 AM
@Júlio Santos but how ?