Class AbstractSerializer<T,​S>

  • Type Parameters:
    T - Type of the object to be inputted for serialization.
    All Implemented Interfaces:
    com.solace.serdes.Serializer<T>, Closeable, AutoCloseable
    Direct Known Subclasses:
    JsonSchemaSerializer

    public abstract class AbstractSerializer<T,​S>
    extends Object
    implements com.solace.serdes.Serializer<T>
    A Serializer base class that processes the configuration objects defined in SerdeProperties.
    Note: A Vertx connection will be made when configuring this Serializer. Vertx threads are non-daemon and will prevent JVM exit, so always remember to call Serializer.close().
    See Also:
    SerdeProperties
    • Method Detail

      • configure

        public void configure​(Map<String,​?> properties)
        Configures the serializer with the given properties. Properties are defined in SerdeProperties
        Note: A Vertx connection will be made when configuring this Serializer. Vertx threads are non-daemon and will prevent JVM exit, so always remember to call Serializer.close().
        Specified by:
        configure in interface com.solace.serdes.Serializer<T>
        Parameters:
        properties - A Map containing configuration properties.
        See Also:
        SerdeProperties
      • serialize

        public byte[] serialize​(String destinationName,
                                T object,
                                Map<String,​Object> headers)
        Serializes the given object and adds the schema ID to the headers.
        Specified by:
        serialize in interface com.solace.serdes.Serializer<T>
        Parameters:
        destinationName - The name of the destination.
        object - The object to be serialized.
        headers - A Map of header properties that can be modified.
        Returns:
        The serialized object as a byte array.
      • serialize

        public byte[] serialize​(String destinationName,
                                T object)
        Serializes the given object.

        Note: Unless the concrete class Serializer (eg, Avro or JsonSchema) supports encoding the schema ID without headers, the schema identifier will not be encoded. In that case use serialize(String, Object, Map) instead.

        Specified by:
        serialize in interface com.solace.serdes.Serializer<T>
        Parameters:
        destinationName - The name of the destination.
        object - The object to be serialized.
        Returns:
        The serialized object as a byte array.
      • close

        public void close()
        Closes this Serializer and any open Vertx connections. This can be called multiple times without adverse effects. Once closed, attempts to serialize will result in a SerializationException. The serializer can be reconfigured and reused after closing.
        Note:
        • Vertx threads are non-daemon and will prevent JVM exit, so always remember to call Serializer.close()
        • This method is idempotent and can be called multiple times safely
        • It can be called even if the serializer hasn't been configured
        • This method is not thread-safe while Serializer.serialize(String, Object, Map) is being called
        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface Closeable
        Specified by:
        close in interface com.solace.serdes.Serializer<T>