Class Serializer<T>

    • 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,
                               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.