Class EnumSerializer<T extends Enum<T>>

All Implemented Interfaces:
ClassResolver

public class EnumSerializer<T extends Enum<T>> extends Serializer<T>
Mainly kept for backwards compatibility, but also serves as ClassResolver for enums.
  • Constructor Details

    • EnumSerializer

      public EnumSerializer(Class<T> c)
  • Method Details

    • deserialize

      @Deprecated public @Nullable T deserialize(String s)
      Deprecated.
      Description copied from class: Serializer
      Deserialises an object from a string returned by this serializer or an earlier version thereof.

      This method should only return null if the input is invalid (i.e. not produced by Serializer.serialize(Object) or an older version of that method)

      This method must only be called from Bukkit's main thread if Serializer.mustSyncDeserialization() returned true.

      Overrides:
      deserialize in class Serializer<T extends Enum<T>>
      Returns:
      The deserialised object or null if the input is invalid. An error message may be logged to specify the cause.
    • mustSyncDeserialization

      public boolean mustSyncDeserialization()
      Description copied from class: Serializer
      Not currently used (everything happens on Bukkit's main thread).
      Specified by:
      mustSyncDeserialization in class Serializer<T extends Enum<T>>
      Returns:
      Whether deserialisation must be done on Bukkit's main thread.
    • canBeInstantiated

      public boolean canBeInstantiated()
      Description copied from class: Serializer
      Returns whether the class should be instantiated using its nullary constructor or not. Return false if the class has no nullary constructor or if you do not have control over the source of the class (e.g. if it's from an API).

      You must override and use Serializer.deserialize(Fields) if this method returns false (Serializer.deserialize(Object, Fields) will no be used anymore in this case).

      Specified by:
      canBeInstantiated in class Serializer<T extends Enum<T>>
    • serialize

      public Fields serialize(T t)
      Description copied from class: Serializer
      Serialises the given object.

      Use return new Fields(this); to emulate the default behaviour.

      This method must be thread-safe. Use Task.callSync(Callable) if you need to serialise on Bukkit's main thread.

      Specified by:
      serialize in class Serializer<T extends Enum<T>>
      Parameters:
      t - The object to serialise
      Returns:
      A Fields object representing the object's fields to serialise. Must not be null.
    • deserialize

      public void deserialize(T o, Fields f)
      Description copied from class: YggdrasilSerializer
      Deserialises an object.

      Use fields.setFields(o); to emulate the default behaviour.

      Specified by:
      deserialize in class Serializer<T extends Enum<T>>
      Parameters:
      o - The object to deserialise as returned by YggdrasilSerializer.newInstance(Class).
      f - The fields read from stream