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
Any class with Java enum type will always be serialised as a String Schema.
I found this to be quite hard to work around as I wished to reuse ModelResolver's logic for bean serialisation and I did not wish to duplicate that logic in a custom ModelConverter.
tl;dr:
Jackson annotations are disregarded when serializing enum classes [feature request]
ModelResolver will serialize a Bean enum class always as a StringSchema disregarding all annotations (@Schema(type = "object") does not work) [a bug imo]
As a QoL change for (2) I would recommend splitting out the bean serialisation from the main resolve method of ModelResolver to allow it to be invoked by subclasses which could then specify a custom base schema.
The text was updated successfully, but these errors were encountered:
I have a dataclass that is used as a field in complex request and response bodies. The class uses
JsonFormat
to have custom serialisation:I would expect it to be serialised as:
Unfortunately it gets serialised as:
I have tried the workarounds listed in #2969, but it seems like most enum class-level Jackson annotations are currently ignored.
The only workaround I found was:
I believe the current problem resides in this line of the
ModelResolver
:swagger-core/modules/swagger-core/src/main/java/io/swagger/v3/core/jackson/ModelResolver.java
Lines 281 to 285 in 0144bff
Any class with Java enum type will always be serialised as a String Schema.
I found this to be quite hard to work around as I wished to reuse
ModelResolver
's logic for bean serialisation and I did not wish to duplicate that logic in a customModelConverter
.tl;dr:
ModelResolver
will serialize a Bean enum class always as aStringSchema
disregarding all annotations (@Schema(type = "object")
does not work) [a bug imo]As a QoL change for (2) I would recommend splitting out the bean serialisation from the main
resolve
method ofModelResolver
to allow it to be invoked by subclasses which could then specify a custom base schema.The text was updated successfully, but these errors were encountered: