Class Serializer<T>

    • Constructor Summary

      Constructors 
      Constructor Description
      Serializer()  
      Serializer​(boolean acceptsNull)  
      Serializer​(boolean acceptsNull, boolean immutable)  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      T copy​(Kryo kryo, T original)
      Returns a copy of the specified object.
      boolean getAcceptsNull()  
      boolean isImmutable()  
      abstract T read​(Kryo kryo, Input input, java.lang.Class<? extends T> type)
      Reads bytes and returns a new object of the specified concrete type.
      void setAcceptsNull​(boolean acceptsNull)
      If true, this serializer will handle writing and reading null values.
      void setImmutable​(boolean immutable)
      If true, the type this serializer will be used for is considered immutable.
      abstract void write​(Kryo kryo, Output output, T object)
      Writes the bytes for the object to the output.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • write

        public abstract void write​(Kryo kryo,
                                   Output output,
                                   T object)
        Writes the bytes for the object to the output.

        This method should not be called directly, instead this serializer can be passed to Kryo write methods that accept a serialier.

        Parameters:
        object - May be null if getAcceptsNull() is true.
      • read

        public abstract T read​(Kryo kryo,
                               Input input,
                               java.lang.Class<? extends T> type)
        Reads bytes and returns a new object of the specified concrete type.

        Before Kryo can be used to read child objects, Kryo.reference(Object) must be called with the parent object to ensure it can be referenced by the child objects. Any serializer that uses Kryo to read a child object may need to be reentrant.

        This method should not be called directly, instead this serializer can be passed to Kryo read methods that accept a serialier.

        Returns:
        May be null if getAcceptsNull() is true.
      • getAcceptsNull

        public boolean getAcceptsNull()
      • setAcceptsNull

        public void setAcceptsNull​(boolean acceptsNull)
        If true, this serializer will handle writing and reading null values. If false, the Kryo framework handles null values and the serializer will never receive null.

        This can be set to true on a serializer that does not accept nulls if it is known that the serializer will never encounter null. Doing this will prevent the framework from writing a byte to denote null.

      • isImmutable

        public boolean isImmutable()
      • setImmutable

        public void setImmutable​(boolean immutable)
        If true, the type this serializer will be used for is considered immutable. This causes copy(Kryo, Object) to return the original object.
      • copy

        public T copy​(Kryo kryo,
                      T original)
        Returns a copy of the specified object. The default implementation returns the original if isImmutable() is true, else throws KryoException. Subclasses can optionall override this method to support Kryo.copy(Object).

        Before Kryo can be used to copy child objects, Kryo.reference(Object) must be called with the copy to ensure it can be referenced by the child objects. A serializer that uses Kryo to copy a child object may need to be reentrant.

        This method should not be called directly, instead this serializer can be passed to Kryo copy methods that accept a serialier.