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

@JsonSubTypes does not work as a field annotation #536

Closed
vtyro opened this issue Jul 21, 2023 · 3 comments
Closed

@JsonSubTypes does not work as a field annotation #536

vtyro opened this issue Jul 21, 2023 · 3 comments
Labels
type: improvement A minor improvement to an existing feature

Comments

@vtyro
Copy link

vtyro commented Jul 21, 2023

Expected Behavior

JSON Serialization/Deserialization of @JsonSubTypes with @SerdeImport for implementation class and generic field should work correctly.

Actual Behaviour

When I use @JsonSubTypes for interface or abstract class and use @SerdeImport for implementation class, than deserializer throw error:
Error decoding JSON stream for type [interFace]: Unable to deserialize type [InterFace]: No default constructor exists io.micronaut.http.codec.CodecException: Error decoding JSON stream for type [interFace]: Unable to deserialize type [InterFace]: No default constructor exists at app//io.micronaut.json.codec.MapperMediaTypeCodec.decode(MapperMediaTypeCodec.java:170) at app//io.micronaut.http.codec.MediaTypeCodec.decode(MediaTypeCodec.java:143) at app//io.micronaut.http.codec.MediaTypeCodec.decode(MediaTypeCodec.java:210) at app//com.example.JacksonSerdeTest.testSerdeImportDeserializeErr1(JacksonSerdeTest.java:43)
It's ok if I using @Serdeable annotation. Another problem with Deserialize when using generic field: data is lost.

Steps To Reproduce

I create simple example in gitlab.

Environment Information

No response

Example Application

https://github.com/vtyro/jackson-serde

Version

4.0.0

@sdelamo
Copy link
Contributor

sdelamo commented Jul 31, 2023

I think this is a Micronaut Serialization not a Micronaut Problem JSON issue right?

@sdelamo sdelamo transferred this issue from micronaut-projects/micronaut-problem-json Jul 31, 2023
yawkat added a commit that referenced this issue Nov 2, 2023
SerdeImport does not add the Serdeable.Deserializable stereotype so findSubtypeDeserializables would not include an imported type in the subtype listing. This PR overrides findSubtypeDeserializables to use isEnabledForDeserialization which handles import properly.

This is for #536, not sure it fixes the full issue though.
@yawkat yawkat added the type: bug Something isn't working label Nov 2, 2023
sdelamo pushed a commit that referenced this issue Nov 2, 2023
SerdeImport does not add the Serdeable.Deserializable stereotype so findSubtypeDeserializables would not include an imported type in the subtype listing. This PR overrides findSubtypeDeserializables to use isEnabledForDeserialization which handles import properly.

This is for #536, not sure it fixes the full issue though.
@yawkat
Copy link
Member

yawkat commented Nov 3, 2023

There is one remaining issue here, we don't support type info annotations on properties like here: https://github.com/vtyro/jackson-serde/blob/master/src/main/java/com/example/err4/Model4.java

I will rename this issue and mark it as improvement, though the #634 was a bug.

@yawkat yawkat added type: improvement A minor improvement to an existing feature and removed type: bug Something isn't working labels Nov 3, 2023
@yawkat yawkat changed the title Micronaut Serde error when using @JsonSubTypes @JsonSubTypes does not work as a field annotation Nov 3, 2023
@dstepanov
Copy link
Contributor

Fixed by #705

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: improvement A minor improvement to an existing feature
Projects
Status: Done
Development

No branches or pull requests

4 participants