Class Adapter<Type,Output>

java.lang.Object
org.polyfrost.oneconfig.api.config.v1.serialize.adapter.Adapter<Type,Output>
Type Parameters:
Type - the type of this adapter
Output - the output type of this adapter, used to avoid unsafe casts for prettier code.
Direct Known Subclasses:
ColorAdapter, ComplexAdapter

public abstract class Adapter<Type,Output> extends Object
While the Config API is equipped with an automatic deserializer (see ObjectSerializer.serialize(Object, boolean)) It is not perfect, and may produce ugly looking results.
For this reason, the Adapter API exists, where you can create your own custom serializer for an object into a map of "simple" objects and string keys.
See Also:
  • Constructor Details

    • Adapter

      public Adapter()
  • Method Details

    • deserialize

      public abstract Type deserialize(Output in)
      Deserialize your object. The form will be identical to what you made in the serialize(Object) method.
      Parameters:
      in - the object (same as deserialize) to create your object from
      Returns:
      the complete object
    • serialize

      public abstract Output serialize(Type in)
      Convert the given object into a serializable form.
      The following types can be returned by this method, and nothing more:
      • Primitive wrappers (any Number, Character, Boolean)
      • A String literal or any class implementing CharSequence
      • An Enum
      • An array of the above types, including primitives (e.g. byte[], int[]..)
      • A List of the above types
      • A Map<String, Object> of the above types, mapped to Strings, which are used as keys.
        Note that 'class' and 'value' are reserved keys and cannot be used.
      • Lists containing lists or maps containing maps (or lists) are also supported.
      Parameters:
      in - the object to serialize
    • getTargetClass

      public abstract Class<Type> getTargetClass()
      Due to Java type erasure, this method is used to get the type of the adapter.
      This is used internally to get what type adapter to use.
    • getOutputClass

      public abstract Class<Output> getOutputClass()
      Due to Java type erasure, this method is used to get the type of the adapter.
      This is used internally to get what type adapter to use.
    • equals

      public final boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object