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

Records with polymorphic types sent from native clients received with no data #37942

Closed
galderz opened this issue Dec 27, 2023 · 4 comments · Fixed by #37993
Closed

Records with polymorphic types sent from native clients received with no data #37942

galderz opened this issue Dec 27, 2023 · 4 comments · Fixed by #37993
Labels
area/jackson Issues related to Jackson (JSON library) area/native-image kind/bug Something isn't working
Milestone

Comments

@galderz
Copy link
Member

galderz commented Dec 27, 2023

Describe the bug

Sending records that include polymorphic types from a native Quarkus app using rest-client to a jvm Quarkus app contains empty data.

The data model uses com.fasterxml.jackson.annotation.JsonSubTypes and com.fasterxml.jackson.annotation.JsonTypeInfo to handle polymorphism, and the types in the reproducer look like this:

public record MammalFamily(Collection<Mammal> mammals) {}

@JsonTypeInfo(use = NAME, include = PROPERTY)
@JsonSubTypes({
    @JsonSubTypes.Type(value=Elephant.class, name = "Elephant"),
    @JsonSubTypes.Type(value=Whale.class, name = "Whale"),
})
public interface Mammal {}

public record Elephant(int hornLength, String continent) implements Mammal {}

public record Whale(double swimSpeed, String color) implements Mammal {}

Expected behavior

Records with polymorphic subtypes should contain all the information when received by the server. E.g.

2023-12-27 12:42:28,586 INFO  [org.acm.ser.MammalResource] (executor-thread-1) Received mammal family:
MammalFamily[mammals=[Whale[swimSpeed=30.0, color=white], Elephant[hornLength=10, continent=africa]]]

Actual behavior

Records with polymorphic subtypes are received by the server but they contain no data:

2023-12-27 12:47:43,323 INFO  [org.acm.ser.MammalResource] (executor-thread-1) Received mammal family:
MammalFamily[mammals=[Whale[swimSpeed=0.0, color=null], Elephant[hornLength=0, continent=null]]]

How to Reproduce?

  1. Checkout reproducer
  2. Run the JVM mode Quarkus server with mvn install -DskipTests && mvn quarkus:run -pl server
  3. Build the native mode Quarkus client and run it with mvn install -DskipTests -Dnative -pl client && ./client/target/client-1.0.0-SNAPSHOT-runner
  4. When the server receives the records from the client, they contain empty information:
2023-12-27 12:47:43,323 INFO  [org.acm.ser.MammalResource] (executor-thread-1) Received mammal family:
MammalFamily[mammals=[Whale[swimSpeed=0.0, color=null], Elephant[hornLength=0, continent=null]]]

In contrast, if the client is running in JVM mode, it all works as expected:

  1. Checkout reproducer
  2. Run the JVM mode Quarkus server with mvn install -DskipTests && mvn quarkus:run -pl server
  3. Run the Quarkus client in JVM mode with mvn quarkus:run -pl server -pl client
  4. The server receives the records from the client with the expected information:
2023-12-27 12:41:29,965 INFO  [org.acm.ser.MammalResource] (executor-thread-1) Received mammal family:
MammalFamily[mammals=[Whale[swimSpeed=30.0, color=white], Elephant[hornLength=10, continent=africa]]]

Output of uname -a or ver

No response

Output of java -version

OpenJDK Runtime Environment GraalVM CE 21+35.1 (build 21+35-jvmci-23.1-b15)

Quarkus version or git rev

3.6.4

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

Avoiding polymorphism can be a temporary workaround if the application supports it.

@galderz galderz added the kind/bug Something isn't working label Dec 27, 2023
@quarkus-bot
Copy link

quarkus-bot bot commented Dec 27, 2023

/cc @zakkak (native-image)

@galderz
Copy link
Member Author

galderz commented Dec 27, 2023

FYI @geoand

@galderz galderz added the area/jackson Issues related to Jackson (JSON library) label Dec 27, 2023
@geoand
Copy link
Contributor

geoand commented Dec 27, 2023

Thanks! I'll have a look next week

@geoand
Copy link
Contributor

geoand commented Jan 3, 2024

#37993 fixes the issue

geoand added a commit to geoand/quarkus that referenced this issue Jan 3, 2024
geoand added a commit that referenced this issue Jan 3, 2024
Register JsonSubTypes.Type values for native mode
@quarkus-bot quarkus-bot bot added this to the 3.7 - main milestone Jan 3, 2024
@gsmet gsmet modified the milestones: 3.7 - main, 3.6.5 Jan 9, 2024
gsmet pushed a commit to gsmet/quarkus that referenced this issue Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/jackson Issues related to Jackson (JSON library) area/native-image kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants