alex
11/06/2019, 11:07 PMClassCastException and debugging shows that line no. 12 does nothing.
What might be the reason, that inline version sometimes (for some calls) skips the cast and returns the same object (i.e. String) instead of reified T?
Classic approach with passing class ref works fine.alex
11/06/2019, 11:11 PMfun getModel(id: Int: CompletableFuture<Model> {
val request: HttpRequest = //...
return sendAsync(request)
}Quy D X Nguyen
11/07/2019, 3:33 AMalex
11/07/2019, 8:33 AMQuy D X Nguyen
11/07/2019, 1:40 PMalex
11/07/2019, 3:28 PMalex
11/08/2019, 9:57 PMprotected inline fun <reified T> sendAsync(
request: HttpRequest,
typeReference: TypeReference<T> = jacksonTypeRef()
): CompletableFuture<T> {
return client.sendAsync(request) { _ ->
BodySubscribers.mapping(BodySubscribers.ofString(StandardCharsets.UTF_8)) {
mapper.readValue(it, typeReference)
}
}.thenApply { it.body() }
}
looks the same, but instead of simple reified T, I'm handing over TypeReference as well.alex
11/08/2019, 10:10 PM