You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using Micronaut serdes, a class with no property but annotated with @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "validation-type") and @JsonSubTypes should contain the JsonType property validation-type when serialized.
Actual Behaviour
When serializing a class that has no property but a property defined by @JsonTypeInfo jackson annotation:
Based on the fact that it works for a class with attributes (e.g., Range in my example), but does not for a class without attributes (e.g., NonEmptyString, I could find, from my example, that:
Range child class is serialized by a CustomObjectSerializer, which is able to get all the attribute, including @JsonTypeInfo
NonEmptyString child class is serialized by a SimpleObjectSerializer, which is not able to
if (!properties.isEmpty() || !jsonGetters.isEmpty()) {
which precisely compute the attribute of @JsonTypeInfo. Unfortunately, it requires properties not to be empty to be honored.. which is not the case of my NonEmptyString child class that has no properties.
Expected Behavior
Using Micronaut serdes, a class with no property but annotated with
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "validation-type")
and@JsonSubTypes
should contain the JsonType propertyvalidation-type
when serialized.Actual Behaviour
When serializing a class that has no property but a property defined by
@JsonTypeInfo
jackson annotation:E.g.:
I was expecting the serialization output to contain the property
validation-type
, but it does contain any field at all, using the Micronaut serdes.The same implementation is working with the
jackson-databind
feature.Using micronaut-serde-jackson
13:46:55.987 [Test worker] INFO com.example.DemoTest - Result: Optional[{validator={}}]
The output does not contain the property
validation-type
.Using micronaut-jackson-databind
13:46:55.987 [Test worker] INFO com.example.DemoTest - Result: Optional[{validator={validation-type=NonEmptyString}}]
The output contains the property
validation-type
as expected.Additional Info
When adding any field to the class, it is serialized as expected using Micronaut serdes:
13:51:04.925 [Test worker] INFO com.example.DemoTest - Result: Optional[{validator={validation-type=NonEmptyStringWithField, anyField=true}}]
The output contains the property
validation-type
as expected.Steps To Reproduce
implementation("io.micronaut.serde:micronaut-serde-jackson")
.implementation("io.micronaut:micronaut-jackson-databind")
.Environment Information
Example Application
https://github.com/loicgreffier/issue-micronaut-serdes
Version
4.1.0
The text was updated successfully, but these errors were encountered: