Open
Description
Currently, the EnumSerializerModule serializes enums by using their toString
:
def serialize(value: Enum, jgen: JsonGenerator, provider: SerializerProvider): Unit =
provider.defaultSerializeValue(value.toString, jgen)
It would be nice to look for a field with a @JsonValue
annotation, and use that instead of toString()
, if it exists.
Example use case:
enum PartOfSpeech(@JsonValue val modelName: String):
case NOUN extends PartOfSpeech("noun")
case ADJECTIVE extends PartOfSpeech("adjective")
case ADVERB extends PartOfSpeech("adverb")
case VERB extends PartOfSpeech("verb")
case UNKNOWN extends PartOfSpeech("unknown")
end PartOfSpeech
I'd like to see noun
instead of NOUN
in the json.
For now, my workaround is to override toString
:
override def toString: String = modelName
This workaround seems to work just fine. I thought it might be a nice bonus to be able to use the @JsonValue
annotation though.
Metadata
Metadata
Assignees
Labels
No labels