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

Missing serde for Number #570

Closed
loicgreffier opened this issue Sep 12, 2023 · 2 comments · Fixed by #765
Closed

Missing serde for Number #570

loicgreffier opened this issue Sep 12, 2023 · 2 comments · Fixed by #765
Labels
type: enhancement New feature or request

Comments

@loicgreffier
Copy link

Expected Behavior

When deserializing a class with a field whose type is an interface annotated with @JsonSubTypes, Micronaut looks for a default constructor on the interface:

io.micronaut.core.convert.exceptions.ConversionErrorException: Failed to convert argument [bodyDto] for value [null] due to: Error decoding property [Validator validator] of type [class com.example.demo.BodyDto]: Unable to deserialize type [Validator validator]: No default constructor exists

You can find a non-working example with Micronaut 4 here: https://github.com/loicgreffier/issue-micronaut-serdes
And a working example with Micronaut 3 here: https://github.com/loicgreffier/micronaut-serdes-working

Actual Behaviour

The deserialization failed on the field annotated with @JsonSubTypes

Steps To Reproduce

  1. Create an interface A with one or more implementations (A1, A2, A3). Define the @JsonTypeInfo and @JsonSubTypes annotations
  2. Create a class B with a field typed with the interface A
  3. Send an object of type B as a body of an HTTP request to a REST endpoint

Environment Information

No response

Example Application

https://github.com/loicgreffier/issue-micronaut-serdes

Version

4.1.0

@graemerocher graemerocher transferred this issue from micronaut-projects/micronaut-core Sep 12, 2023
@yawkat
Copy link
Member

yawkat commented Sep 12, 2023

The main issue is your @Introspected(classes = Number.class). That breaks the introspection for the class it's on (Range) which breaks further serialization.

Removing that is not enough though. Serde does not have a deserializer for Number atm. So I will leave this issue open.

@yawkat yawkat added the type: enhancement New feature or request label Sep 12, 2023
@yawkat yawkat changed the title No default constructor exists when using @JsonSubTypes on Micronaut 4 Missing serde for Number Sep 12, 2023
@loicgreffier
Copy link
Author

I confirm that implementing my own beans Deserializer<Number> and Serializer<Number> seems to do the trick for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants