Interface EntitySerializer<T>

Type Parameters:
T - The type of the serialized data.
All Known Implementing Classes:
DefaultEntitySerializer

public interface EntitySerializer<T>
A generic behaviour for de/serializing catnip entities. The default implementation is DefaultEntitySerializer, which does nothing but throw on method calls. You must provide a serializer that properly handles de/serialization requests.
Since:
9/12/19.
Author:
amy
  • Method Summary

    Modifier and Type
    Method
    Description
    <E extends Entity>
    E
    deserialize(T data, Class<E> as)
    Deserializes the given data into an entity of the right type.
    serialize(Entity entity)
    Serializes the given entity.
  • Method Details

    • serialize

      @Nonnull @CheckReturnValue T serialize(@Nonnull Entity entity)
      Serializes the given entity. This method should handle things like converting snowflakes into strings, if the serialization method in use (ex. JSON) doesn't support bigints.

      It is strongly recommended that you add in functionality to determine the catnip version that an entity was serialized with, so as to avoid potential version mismatch errors.

      Parameters:
      entity - The entity to serialize.
      Returns:
      The serialized entity data.
    • deserialize

      @Nonnull @CheckReturnValue <E extends Entity> E deserialize(@Nonnull T data, @Nonnull Class<E> as)
      Deserializes the given data into an entity of the right type. This method should handle things like converting strings into snowflakes, if the serialization method in use (ex. JSON) doesn't support bigints; that is, it should effectively undo any data transformations done in serialize(Entity).

      It is strongly recommended that you add in functionality to determine the catnip version that an entity was serialized with, so as to avoid potential version mismatch errors.

      Type Parameters:
      E - The type of the target entity.
      Parameters:
      data - The data to deserialize.
      as - The type of entity to deserialize data into.
      Returns:
      The entity deserialized from the given data.