Marc Knaup
06/23/2019, 2:35 PMHttpResponsePipeline
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.e5l
06/24/2019, 6:34 AMattributes
instead.Marc Knaup
06/24/2019, 10:11 AM@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:
@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:
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.