The client's `HttpResponsePipeline` should allow p...
# ktor
m
The client's
HttpResponsePipeline
should allow passing additional info - not just a
TypeInfo
. I'd like to pass the
KSerializer
which should be used for example since it's for a generic type. The feature or json serializer could then use the additional info to correctly deserialize the response.
e
Hi @Marc Knaup, could you describe your use case? Maybe you can use
attributes
instead.
m
Hey @e5l, I've written a small API client for Airtable. In Airtable, records always have the same structure:
Copy code
@Serializable
data class AirtableRecord<Fields : Any>(
	val createdTime: Instant,
	val fields: Fields,
	val id: String
)
Fields
depends on the actual table you're accessing. Like this for example:
Copy code
@Serializable
data class TimeTrackingFields(

	@SerialName("Description")
	val description: String,

	@SerialName("Employee ID")
	val employeeId: String,

	@SerialName("End Time")
	val endTime: Instant,

	@SerialName("Planday ID")
	val plandayId: String,

	@SerialName("Start Time")
	val startTime: Instant,

	@SerialName("Sync Time")
	val syncTime: Instant
)
So I can make the API calls generic and type-safe:
Copy code
suspend inline fun <reified Fields : Any> createRecord(tableName: String, fields: Fields): AirtableRecord<Fields> = …
suspend inline fun <reified Fields : Any> updateRecord(tableName: String, recordId: String, fields: Fields): AirtableRecord<Fields> = …
But in that case the API response (
AirtableRecord<Fields>
) would require a serializer for a generic type. With
TypeInfo
I'm not able to get the concrete type of
Fields
. I only get the
TypeVariable
. My solution for now is to avoid
JsonFeature
and do the parsing & serializing directly in my client.