I have a generic record that I use to send enum values with a description to my front-end:
public record EnumJson<E extends Enum<E>>(E value, String description) {
}
I have a single endpoint in which I provide many different enums in one response. It looks a bit like this (but more complex):
public record Enums(
List<YesNo> yesNo,
List<RedBlue> redBlue,
List<UpDown> upDown, ...) {
}
For many of these enums, OpenAPI’s default definition is fine (serialize using Enum.name()
). However, for a handful of these enums, I’d like to customize serialization, and have the OpenAPI yaml reflect that. I’m looking for some method to control the way E
is serialized from Enums
. Perhaps with an annotation like:
public record Enums(
List<YesNo> yesNo,
List<RedBlue> redBlue,
List<@CustomizeSchemaOfValueInUpDownHere UpDown> upDown, ...) {
}
I currently have a copy of EnumJson
as follows:
public record UpDownEnumJson<E extends Enum<E>>(@Schema(...) E value, String description) {
}
However, it feels like there must be a better alternative (especially because I require quite a number of these copies).