Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RxJava2 module not working in GraalVM native image #32

Closed
auke- opened this issue Dec 27, 2021 · 0 comments · Fixed by #33
Closed

RxJava2 module not working in GraalVM native image #32

auke- opened this issue Dec 27, 2021 · 0 comments · Fixed by #33

Comments

@auke-
Copy link
Contributor

auke- commented Dec 27, 2021

When using the Micronaut RxJava2 module in a Micronaut 3.x application the service always returns an empty json object ({}) when the controller method uses a RxJava2 return type (e.g. io.reactivex.Single).

Since this isn't the case for Reactor and RxJava3 types (they work as expected) I compared the micronaut-rxjava2 and micronaut-rxjava3 projects and it seems like the GraalVM reflection configuration is missing in the micronaut-rxjava2 jar, probably due to the absence of the micronaut-graal annotation processor in micronaut-rxjava2/build.gradle (see micronaut-rxjava3/build.gradle).

The trace logs shows (when returning io.reactivex.Single<List<MyObject>>):

[io-executor-thread-1] TRACE i.m.h.s.netty.RoutingInBoundHandler - Encoding emitted response object [io.micronaut.rxjava2.instrument.RxInstrumentedSingle@1fffc00c] using codec: io.micronaut.json.codec.JsonMediaTypeCodec@1221bd44

While for both Reactor and RxJava3 based return types the actual objects are shown (when returning io.reactivex.rxjava3.core.Single<List<MyObject>> or reactor.core.publisher.Mono<List<MyObject>>):

[io-executor-thread-1] TRACE i.m.h.s.netty.RoutingInBoundHandler - Encoding emitted response object [[<MyObject>,<MyObject>]] using codec: io.micronaut.json.codec.JsonMediaTypeCodec@467a29cd

I was under the impression that Micronaut didn't use reflection for json serialization but uses the BeanIntrospection classes generated based on the @Introspected annotation, but it looks like it is missing reflection information for the RxJava2 classes.

Note that adding @TypeHint(value = io.reactivex.Single.class) to the application works around this issue.

Steps to Reproduce

  1. Create a Micronaut project with the GraalVM feature (e.g. using https://guides.micronaut.io/latest/micronaut-creating-first-graal-app-maven-java.html)
  2. Add the micronaut-rxjava2 dependency
  3. Add a method to the controller which returns a io.reactivex.Single
  4. Build the native image and invoke the service

Expected Behaviour

The service should return the objects created in the controller method

Actual Behaviour

An empty json object ({}) is returned

Environment Information

  • Operating System: MacOS
  • Micronaut Version: v3.2.3
  • JDK Version: GraalVM 17.0.1+12-jvmci-21.3-b05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant