Jeff
11/15/2024, 6:30 PMprivate val _client: HttpClient = HttpClient {
install(ContentNegotiation) {
json(Json {
this.isLenient = true
this.ignoreUnknownKeys = true
})
}
}
and an example generic method I am trying to create is like this
suspend inline fun <reified T> get(builder: HttpRequestBuilder): T? {
val response = _client.get(builder)
....
return response.body()
}
Where when using this method you give the type the response should be (deserialized to an object from json). The IDE is telling me
Public-API inline function cannot access non-public-APIon the
client
object, I dont want that public to be used outside of this class so what are my options herephldavies
11/15/2024, 6:46 PMinternal
and add the @PublishedApi
annotation to allow it to be used from within a public inline methodJeff
11/15/2024, 7:04 PMphldavies
11/15/2024, 7:11 PMJeff
11/15/2024, 7:25 PMsuspend fun <T> get(builder: HttpRequestBuilder, typeInfo: TypeInfo): T? {
val response = _client.get(builder)
....
return response.body(typeInfo)
}
myHttpClient.get<TestData>(builder, typeInfo<TestData>())
phldavies
11/15/2024, 7:26 PMsuspend inline fun <reified T> get(builder: HttpRequestBuilder): T? = get(builder, typeInfo<T>())