Class ScalaEnumSerde<E extends scala.reflect.Enum>
- Type Parameters:
E- The enum type
- All Implemented Interfaces:
io.micronaut.serde.Deserializer<E>, io.micronaut.serde.Serializer<E>, io.micronaut.serde.util.CustomizableDeserializer<E>, io.micronaut.serde.util.CustomizableSerializer<E>
enum, which is a name in a document as a Java enum is.
A Scala 3 enum is not a java.lang.Enum unless it says so, so the serializer Micronaut
Serialization has for enums does not apply and the case is introspected as a bean instead. The
case objects have no properties, so nothing useful comes out and nothing at all goes back
in.
The name written is the one the case declares -- its product prefix, not its toString,
which an enum may override for display. Reading it back goes through the companion's
generated valueOf, which is the same lookup the language itself uses, so a name the
enum does not have is rejected here rather than becoming a null the caller meets later.
The type parameter is what makes one bean answer for every enum. A serializer is chosen by
what it can accept, so naming scala.reflect.Enum outright would do for writing; a
deserializer is chosen by what it can produce, and one that produces scala.reflect.Enum
cannot stand in where a particular enum was asked for. Declaring the bound as a type variable
instead publishes the bean under a type variable rather than a fixed type, which matches any
subtype -- the same device Micronaut Serialization's own enum support uses.
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.micronaut.serde.Deserializer
io.micronaut.serde.Deserializer.DecoderContextNested classes/interfaces inherited from interface io.micronaut.serde.Serializer
io.micronaut.serde.Serializer.EncoderContext -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionio.micronaut.serde.Deserializer<E> createSpecific(io.micronaut.serde.Deserializer.DecoderContext context, io.micronaut.core.type.Argument<? super E> type) io.micronaut.serde.Serializer<E> createSpecific(io.micronaut.serde.Serializer.EncoderContext context, io.micronaut.core.type.Argument<? extends E> type) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.micronaut.serde.util.CustomizableDeserializer
deserialize, deserializeNullable, getDefaultValueMethods inherited from interface io.micronaut.serde.util.CustomizableSerializer
isAbsent, isEmpty, serializeMethods inherited from interface io.micronaut.serde.Serializer
isDefault
-
Constructor Details
-
ScalaEnumSerde
public ScalaEnumSerde()
-
-
Method Details
-
createSpecific
-
createSpecific
public io.micronaut.serde.Deserializer<E> createSpecific(io.micronaut.serde.Deserializer.DecoderContext context, io.micronaut.core.type.Argument<? super E> type) throws io.micronaut.serde.exceptions.SerdeException - Specified by:
createSpecificin interfaceio.micronaut.serde.Deserializer<E extends scala.reflect.Enum>- Throws:
io.micronaut.serde.exceptions.SerdeException
-