Joost Klitsie
05/25/2022, 2:12 PMabstract class ApiDataSource<T>(private val httpClient: HttpClient) {
fun update(value: T) {
httpClient.put {
setBody(value) // <-- T needs to be reified
}
}
}
As of course setBody needs to have a reified type. I was looking through the functions, and nowhere can I pass a type or kclass. Am I missing something?
Also, a workaround would be to serialize the body myself (by passing the KSerializer in the constructor and Json and setBody with the serialized text), but would this be preferable? I rather serialize through using the ContentNegotiation pluginRustam Siniukov
05/25/2022, 2:47 PMfun setBody(body: Any, type: TypeInfo) . So far you can set request.body and request.bodyType manually, but you will need to opt-in to usage of properties marked with @InternalAPIJoost Klitsie
05/26/2022, 2:05 PMJoost Klitsie
05/26/2022, 2:08 PMget ->`doGet` and update -> doUpdate so I map the implementation's method to this inline function in the base class: override fun update(value: SomeDataClass) = doUpdate(value) But then for every class I need to provide these overrides so that is extra effort, especially if I change the interface.