Class Serializer

Direct Known Subclasses:
ArraySerializer, BooleanSerializer, ByteSerializer, CharSerializer, ClientRegistrationMessage.ClientRegistrationSerializer, CollectionSerializer, DateSerializer, DisconnectMessage.DisconnectSerializer, DoubleSerializer, EnumSerializer, FieldSerializer, FloatSerializer, GZIPSerializer, IntSerializer, LongSerializer, MapSerializer, RmiSerializer, SavableSerializer, SerializableSerializer, ShortSerializer, StringSerializer, Vector3Serializer, ZIPSerializer

public abstract class Serializer extends Object
The main serializer class, which will serialize objects such that they can be sent across the network. Serializing classes should extend this to provide their own serialization.
  • Field Details

    • log

      protected static final Logger log
  • Constructor Details

    • Serializer

      public Serializer()
  • Method Details

    • initialize

      public static void initialize()
    • setStrictRegistration

      public static void setStrictRegistration(boolean b)
      When set to true, classes that do not have intrinsic IDs in their @Serializable will not be auto-registered during write. Defaults to true since this is almost never desired behavior with the way this code works. Set to false to get the old permissive behavior.
    • registerClass

      public static SerializerRegistration registerClass(Class cls)
    • registerClasses

      public static void registerClasses(Class... classes)
    • setReadOnly

      public static void setReadOnly(boolean b)
      Can put the registry in a read-only state such that additional attempts to register classes will fail. This can be used by servers to lock the registry to avoid accidentally registering classes after a full registry set has been compiled.
    • isReadOnly

      public static boolean isReadOnly()
    • registerClassForId

      public static SerializerRegistration registerClassForId(short id, Class cls, Serializer serializer)
      Directly registers a class for a specific ID. Generally, use the regular registerClass() method. This method is intended for framework code that might be maintaining specific ID maps across client and server.
    • registerClass

      public static SerializerRegistration registerClass(Class cls, boolean failOnMiss)
      Registers the specified class. The failOnMiss flag controls whether this method returns null for failed registration or throws an exception.
    • registerPackage

      @Deprecated public static SerializerRegistration[] registerPackage(String pkgName)
      This cannot be implemented in a reasonable way that works in all deployment methods.
    • registerClass

      public static SerializerRegistration registerClass(Class cls, Serializer serializer)
    • getExactSerializer

      public static Serializer getExactSerializer(Class cls)
    • getSerializer

      public static Serializer getSerializer(Class cls)
    • getSerializer

      public static Serializer getSerializer(Class cls, boolean failOnMiss)
    • getSerializerRegistrations

      public static Collection<SerializerRegistration> getSerializerRegistrations()
    • getExactSerializerRegistration

      public static SerializerRegistration getExactSerializerRegistration(Class cls)
    • getSerializerRegistration

      public static SerializerRegistration getSerializerRegistration(Class cls)
    • getSerializerRegistration

      public static SerializerRegistration getSerializerRegistration(Class cls, boolean failOnMiss)
    • readClass

      public static SerializerRegistration readClass(ByteBuffer buffer)
      Read the class from given buffer and return its SerializerRegistration.
      buffer - The buffer to read from.
      The SerializerRegistration, or null if non-existent.
    • readClassAndObject

      public static Object readClassAndObject(ByteBuffer buffer) throws IOException
      Read the class and the object.
      buffer - Buffer to read from.
      The Object that was read.
      IOException - If serialization failed.
    • writeClass

      public static SerializerRegistration writeClass(ByteBuffer buffer, Class type) throws IOException
      Write a class and return its SerializerRegistration.
      buffer - The buffer to write the given class to.
      type - The class to write.
      The SerializerRegistration that's registered to the class.
    • writeClassAndObject

      public static void writeClassAndObject(ByteBuffer buffer, Object object) throws IOException
      Write the class and object.
      buffer - The buffer to write to.
      object - The object to write.
      IOException - If serializing fails.
    • readObject

      public abstract <T> T readObject(ByteBuffer data, Class<T> c) throws IOException
      Read an object from the buffer, effectively deserializing it.
      data - The buffer to read from.
      c - The class of the object.
      The object read.
      IOException - If deserializing fails.
    • writeObject

      public abstract void writeObject(ByteBuffer buffer, Object object) throws IOException
      Write an object to the buffer, effectively serializing it.
      buffer - The buffer to write to.
      object - The object to serialize.
      IOException - If serializing fails.
    • initialize

      public void initialize(Class clazz)
      Registration for when a serializer may need to cache something. Override to use.
      clazz - The class that has been registered to the serializer.