Package io.protostuff.runtime
Class EnumIO<E extends Enum<E>>
java.lang.Object
io.protostuff.runtime.EnumIO<E>
- All Implemented Interfaces:
PolymorphicSchema.Factory
- Direct Known Subclasses:
EnumIO.ByName
,EnumIO.ByNumber
Determines how enums are serialized/deserialized. Default is BY_NUMBER. To enable BY_NAME, set the property
"protostuff.runtime.enums_by_name=true".
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
EnumIO.ByName<E extends Enum<E>>
Reads the enum by its name.static final class
EnumIO.ByNumber<E extends Enum<E>>
Reads the enum by its number. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Field
private static final Field
private final String[]
The enum class.private MapSchema.MessageFactory
private CollectionSchema.MessageFactory
final ArraySchemas.Base
final IdStrategy
private final int[]
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetByAlias
(String alias) getByTag
(int tag) (package private) static Class
<?> getElementTypeFromEnumSet
(Object enumSet) Retrieves the enum key type from the EnumMap via reflection.Returns the factory for an EnumMap (lazy).Returns the factory for an EnumSet (lazy).(package private) static Class
<?> getKeyTypeFromEnumMap
(Object enumMap) Retrieves the enum key type from the EnumMap via reflection.int
newEnumIO
(Class<?> enumClass, IdStrategy strategy) Returns an emptyEnumMap
.private static <E extends Enum<E>>
MapSchema.MessageFactorynewEnumMapFactory
(EnumIO<E> eio) Returns an emptyEnumSet
.private static <E extends Enum<E>>
CollectionSchema.MessageFactorynewEnumSetFactory
(EnumIO<E> eio) newSchema
(Class<?> typeClass, IdStrategy strategy, PolymorphicSchema.Handler handler) abstract E
Read the enum from the input.static void
transfer
(Pipe pipe, Input input, Output output, int number, boolean repeated, IdStrategy strategy) Transfers theEnum
from the input to the output.void
Writes theEnum
to the output.
-
Field Details
-
__keyTypeFromEnumMap
-
__elementTypeFromEnumSet
-
enumClass
The enum class. -
strategy
-
genericElementSchema
-
enumSetFactory
-
enumMapFactory
-
alias
-
tag
private final int[] tag -
valueByAliasMap
-
valueByTagMap
-
-
Constructor Details
-
EnumIO
-
-
Method Details
-
getKeyTypeFromEnumMap
Retrieves the enum key type from the EnumMap via reflection. This is used byObjectSchema
. -
getElementTypeFromEnumSet
Retrieves the enum key type from the EnumMap via reflection. This is used byObjectSchema
. -
newEnumIO
-
writeTo
Writes theEnum
to the output.- Throws:
IOException
-
transfer
public static void transfer(Pipe pipe, Input input, Output output, int number, boolean repeated, IdStrategy strategy) throws IOException Transfers theEnum
from the input to the output.- Throws:
IOException
-
newEnumSetFactory
-
newEnumMapFactory
-
newSchema
public PolymorphicSchema newSchema(Class<?> typeClass, IdStrategy strategy, PolymorphicSchema.Handler handler) - Specified by:
newSchema
in interfacePolymorphicSchema.Factory
-
getTag
-
getAlias
-
getByTag
-
getByAlias
-
getEnumSetFactory
Returns the factory for an EnumSet (lazy). -
getEnumMapFactory
Returns the factory for an EnumMap (lazy). -
newEnumSet
Returns an emptyEnumSet
. -
newEnumMap
Returns an emptyEnumMap
. -
readFrom
Read the enum from the input.- Throws:
IOException
-