micronaut-projects / micronaut-core

Micronaut Application Framework
http://micronaut.io
Apache License 2.0
6.06k stars 1.06k forks source link

Error decoding stream for type [class io.reactivex.Single] with Micronaut 3 and GraalVM in AWS Lambda #6261

Open athkalia opened 3 years ago

athkalia commented 3 years ago

Expected Behavior

I am using an RxJava 2 io.reactivex.Single type as return type of a Micronaut declarative HTTP client (with annotation @Client). An example looks like this:

@Client("https://some-api.com")
interface Client {

@Get("/pet")
fun getPet(@Header("Authorization") authorization: String): Single<Pet>
}

(I do need to import the dependencies io.micronaut.rxjava2:micronaut-rxjava2-http-client and io.reactivex.rxjava2:rxjava )

This works fine, except when I am using the native GraalVM images. Then I get the following error

Actual Behaviour

Type [com.project.Client$Intercepted] executed with error: Error decoding HTTP response body: Error decoding stream for type [class io.reactivex.Single]: Cannot construct instance of `io.reactivex.Single` (no Creators, like default constructor, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information

I am wondering if as part of moving the RxJava 2 out of the platform, some reflection configuration for GraalVM was accidentally removed altogether or something?

Steps To Reproduce

No response

Environment Information

This is happening in AWS Lambda

Example Application

No response

Version

3.0.2

graemerocher commented 2 years ago

@athkalia could you provide an example that reproduces the problem?

adamkobor commented 2 years ago

@graemerocher I have the exact same problem in my pet-project: https://github.com/kuvasz-uptime/kuvasz With a regular docker image there is no problem around declarative clients annotated with @Client, however in this file the sendMessage call always fails when I run the native image: https://github.com/kuvasz-uptime/kuvasz/blob/2297709d97ee0d9ee61df17ab3b37b463fb56338/src/main/kotlin/com/kuvaszuptime/kuvasz/services/TelegramAPIService.kt

The weirdest part is that the HTTP request is successful (I get the messages on Telegram), but the retry logic kicks in and sends the request again and again, because of the following exception:

Caused by: io.micronaut.http.codec.CodecException: Error decoding stream for type [class io.reactivex.Single]: Cannot construct instance of `io.reactivex.Single` (no Creators, like default constructor, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information

Also, there is a very similar approach here: https://github.com/kuvasz-uptime/kuvasz/blob/2297709d97ee0d9ee61df17ab3b37b463fb56338/src/main/kotlin/com/kuvaszuptime/kuvasz/services/SlackWebhookService.kt but this client call doesn't fail in a native image.

athkalia commented 2 years ago

FYI I upgraded to RxJava 3 and everything worked