Class AvroSerializer<T>

  • Type Parameters:
    T - The type to be serialized.
    All Implemented Interfaces:
    Serializable

    public class AvroSerializer<T>
    extends org.apache.flink.api.common.typeutils.TypeSerializer<T>
    A serializer that serializes types via Avro.

    The serializer supports:

    • efficient specific record serialization for types generated via Avro
    • serialization via reflection (ReflectDatumReader / -Writer)
    • serialization of generic records via GenericDatumReader / -Writer

    The serializer instantiates them depending on the class of the type it should serialize.

    Important: This serializer is NOT THREAD SAFE, because it reuses the data encoders and decoders which have buffers that would be shared between the threads if used concurrently

    See Also:
    Serialized Form
    • Constructor Detail

      • AvroSerializer

        public AvroSerializer​(Class<T> type)
        Creates a new AvroSerializer for the type indicated by the given class. This constructor is intended to be used with SpecificRecord or reflection serializer. For serializing GenericData.Record use AvroSerializer(Class, Schema)
      • AvroSerializer

        public AvroSerializer​(Class<T> type,
                              org.apache.avro.Schema schema)
        Creates a new AvroSerializer for the type indicated by the given class. This constructor is expected to be used only with GenericData.Record. For SpecificRecord or reflection serializer use AvroSerializer(Class)
    • Method Detail

      • isImmutableType

        public boolean isImmutableType()
        Specified by:
        isImmutableType in class org.apache.flink.api.common.typeutils.TypeSerializer<T>
      • getLength

        public int getLength()
        Specified by:
        getLength in class org.apache.flink.api.common.typeutils.TypeSerializer<T>
      • createInstance

        public T createInstance()
        Specified by:
        createInstance in class org.apache.flink.api.common.typeutils.TypeSerializer<T>
      • serialize

        public void serialize​(T value,
                              org.apache.flink.core.memory.DataOutputView target)
                       throws IOException
        Specified by:
        serialize in class org.apache.flink.api.common.typeutils.TypeSerializer<T>
        Throws:
        IOException
      • deserialize

        public T deserialize​(org.apache.flink.core.memory.DataInputView source)
                      throws IOException
        Specified by:
        deserialize in class org.apache.flink.api.common.typeutils.TypeSerializer<T>
        Throws:
        IOException
      • deserialize

        public T deserialize​(T reuse,
                             org.apache.flink.core.memory.DataInputView source)
                      throws IOException
        Specified by:
        deserialize in class org.apache.flink.api.common.typeutils.TypeSerializer<T>
        Throws:
        IOException
      • copy

        public T copy​(T from)
        Specified by:
        copy in class org.apache.flink.api.common.typeutils.TypeSerializer<T>
      • copy

        public T copy​(T from,
                      T reuse)
        Specified by:
        copy in class org.apache.flink.api.common.typeutils.TypeSerializer<T>
      • copy

        public void copy​(org.apache.flink.core.memory.DataInputView source,
                         org.apache.flink.core.memory.DataOutputView target)
                  throws IOException
        Specified by:
        copy in class org.apache.flink.api.common.typeutils.TypeSerializer<T>
        Throws:
        IOException
      • snapshotConfiguration

        public org.apache.flink.api.common.typeutils.TypeSerializerSnapshot<T> snapshotConfiguration()
        Specified by:
        snapshotConfiguration in class org.apache.flink.api.common.typeutils.TypeSerializer<T>
      • duplicate

        public org.apache.flink.api.common.typeutils.TypeSerializer<T> duplicate()
        Specified by:
        duplicate in class org.apache.flink.api.common.typeutils.TypeSerializer<T>
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in class org.apache.flink.api.common.typeutils.TypeSerializer<T>
      • equals

        public boolean equals​(Object obj)
        Specified by:
        equals in class org.apache.flink.api.common.typeutils.TypeSerializer<T>