Class Serializer<I,O,D>

java.lang.Object
me.hsgamer.hscore.serializer.Serializer<I,O,D>
Type Parameters:
I - the type of the input object
O - the type of the output object
D - the type of the data

public abstract class Serializer<I,O,D> extends Object
The serializer
  • Constructor Details

    • Serializer

      protected Serializer(Class<I> inputClass, Class<O> outputClass, Class<D> dataClass)
      Create a new serializer
      Parameters:
      inputClass - the class of the input
      outputClass - the class of the output
      dataClass - the class of the data
  • Method Details

    • register

      public void register(String type, Class<? extends D> dataClass, Function<I,D> dataFunction)
      Register a new data type
      Parameters:
      type - the type
      dataClass - the data class
      dataFunction - the data function
    • register

      public void register(Class<? extends D> dataClass, Function<I,D> dataFunction)
      Register a new data type, without specifying the type. The type will be the class name, or the value of SerializerType if the class is annotated with it.
      Parameters:
      dataClass - the data class
      dataFunction - the data function
    • register

      public void register(Class<? extends D> dataClass)
      Register a new data type, without specifying the type and the data function. The type will be the class name, or the value of SerializerType if the class is annotated with it. The data function will be the static method annotated with SerializerFunction.
      Parameters:
      dataClass - the data class
      Throws:
      IllegalArgumentException - if the data function is not found
    • unregister

      public void unregister(String type)
      Unregister a data type
      Parameters:
      type - the type
    • unregister

      public void unregister(Class<? extends D> dataClass)
      Unregister a data type
      Parameters:
      dataClass - the data class
    • convertOut

      protected abstract O convertOut(D data, I input)
      Convert the data to the output
      Parameters:
      data - the data
      input - the input
      Returns:
      the output
    • convert

      protected abstract I convert(D data, String type, O output)
      Convert the data to the input
      Parameters:
      data - the data
      type - the type
      output - the output
      Returns:
      the input
    • getData

      protected abstract D getData(O output)
      Get the data from the output
      Parameters:
      output - the output
      Returns:
      the data
    • getType

      protected abstract String getType(I input)
      Get the type from the input
      Parameters:
      input - the input
      Returns:
      the type
    • deserialize

      public O deserialize(I input)
      Deserialize the input
      Parameters:
      input - the input
      Returns:
      the output
    • serialize

      public I serialize(O to)
      Serialize the output
      Parameters:
      to - the output
      Returns:
      the input