Class CollectionSerializer<T extends Collection>

    • Constructor Detail

      • CollectionSerializer

        public CollectionSerializer()
    • Method Detail

      • setElementsCanBeNull

        public void setElementsCanBeNull​(boolean elementsCanBeNull)
        Parameters:
        elementsCanBeNull - False if all elements are not null. This saves 1 byte per element if elementClass is set. True if it is not known (default).
      • setElementClass

        public void setElementClass​(Class elementClass)
        The concrete class of the collection elements, or null if it is not known. This saves 1-2 bytes per element. Only set to a non-null value if the elements in the collection are known to all be instances of this class (or null).
      • getElementClass

        public Class getElementClass()
      • setElementSerializer

        public void setElementSerializer​(Serializer elementSerializer)
        The serializer to be used for elements in collection, or null to use the serializer registered with Kryo for each element's type. Default is null.
      • getElementSerializer

        public Serializer getElementSerializer()
      • write

        public void write​(Kryo kryo,
                          Output output,
                          T collection)
        Description copied from class: Serializer
        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.

        Specified by:
        write in class Serializer<T extends Collection>
        collection - May be null if Serializer.getAcceptsNull() is true.
      • read

        public T read​(Kryo kryo,
                      Input input,
                      Class<? extends T> type)
        Description copied from class: Serializer
        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.

        Specified by:
        read in class Serializer<T extends Collection>
        Returns:
        May be null if Serializer.getAcceptsNull() is true.
      • createCopy

        protected T createCopy​(Kryo kryo,
                               T original)
        Used by copy(Kryo, Collection) to create the new object. This can be overridden to customize object creation, eg to call a constructor with arguments. The default implementation uses Kryo.newInstance(Class).
      • copy

        public T copy​(Kryo kryo,
                      T original)
        Description copied from class: Serializer
        Returns a copy of the specified object. The default implementation returns the original if Serializer.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.

        Overrides:
        copy in class Serializer<T extends Collection>