Package com.solace.serdes.common
Class AbstractSerializer<T,S>
- java.lang.Object
-
- com.solace.serdes.common.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 inSerdeProperties
.
Note: A Vertx connection will be made when configuring thisSerializer
. Vertx threads are non-daemon and will prevent JVM exit, so always remember to callSerializer.close()
.- See Also:
SerdeProperties
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes thisSerializer
and any open Vertx connections.void
configure(Map<String,?> properties)
Configures the serializer with the given properties.byte[]
serialize(String destinationName, T object)
Serializes the given object.byte[]
serialize(String destinationName, T object, Map<String,Object> headers)
Serializes the given object and adds the schema ID to the headers.
-
-
-
Method Detail
-
configure
public void configure(Map<String,?> properties)
Configures the serializer with the given properties. Properties are defined inSerdeProperties
Note: A Vertx connection will be made when configuring thisSerializer
. Vertx threads are non-daemon and will prevent JVM exit, so always remember to callSerializer.close()
.- Specified by:
configure
in interfacecom.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 interfacecom.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 interfacecom.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 thisSerializer
and any open Vertx connections. This can be called multiple times without adverse effects. Once closed, attempts to serialize will result in aSerializationException
. 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 interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfacecom.solace.serdes.Serializer<T>
- Vertx threads are non-daemon and will prevent JVM exit, so always remember to call
-
-