Class AdvancedEnumSerializer<E extends Enum<E>>

java.lang.Object
com.mrivanplays.annotationconfig.core.serialization.AdvancedEnumSerializer<E>
Type Parameters:
E - enum class
All Implemented Interfaces:
FieldTypeSerializer<E>

public final class AdvancedEnumSerializer<E extends Enum<E>> extends Object implements FieldTypeSerializer<E>
Enum serializer, which uses different tricks to serialize enum constants to user-friendly values for configs, and also to read them properly.

Lets be real, every developer tried or is going to try to serialize enum constants, so they are more user-friendly to be configured. Yet everyone who tried wasn't really able to go farther than accepting this input: enum_constant for an enum constant of ENUM_CONSTANT. As already mentioned, this serializer uses tricks in order to accept literally every output possible. Say you have an enum constant of ACCEPT_ONLY_TRUE. This serializer serializes this constant as accept only true, but upon deserialization, the serializer accepts literally any possible way of combining these words. This basically means it will accept only accept true, accept true only, etc., and of course the input as a regular enum constant e.g. ACCEPT_ONLY_TRUE and accept_only_true.

Example: Say you have an enum of:


 public enum Option {
   ACCEPT_TRUE,
   ACCEPT_FALSE,
   ACCEPT_BOTH,
   DO_NOT_ACCEPT_TRUE,
   DO_NOT_ACCEPT_FALSE,
   DO_NOT_ACCEPT_BOTH
 }
 
and you want to use AdvancedEnumSerializer to serialize it, you just register it using the SerializerRegistry. An example of this is:

 SerializerRegistry.INSTANCE.registerSerializer(Option.class, AdvancedEnumSerializer.forEnum(Option.class));
 
Since:
2.0.0
Author:
MrIvanPlays