Ktor: HttpResponse with Deserialized objects

Created on 7 May 2020  路  2Comments  路  Source: ktorio/ktor

Subsystem
Client

Is your feature request related to a problem? Please describe.
When using serialization such as kotlinx serialization you have to choose between if you want nice deserialized objects returned with

val response:MyObject = client.get<MyObject>(url)

or if you want to the whole response with HttpResponse and the manually deserialize the response.

val response:HttpResponse = client.get(url)

There is no way that I currently see where you can have both the deserialized object and the response information ie. status code, headers etc. that you can get from the HttpResponse

Describe the solution you'd like
A solution that would be optimal would be where the HttpResponse wraps a generic type like HttpResponse<MyObject> and then you can have all the response information AND your deserialized objects at the same time

Motivation to include to ktor
This would allow users to not have to choose between convenience or having to handle everything yourself just to get response information

feature

Most helpful comment

Hi @tyczj, thanks for the report. Could you try using the HttpResponse.receive<MyObject> method?
It should work as you expect.

All 2 comments

Hi @tyczj, thanks for the report. Could you try using the HttpResponse.receive<MyObject> method?
It should work as you expect.

oh nice I didn't know this, thank you!

Was this page helpful?
0 / 5 - 0 ratings