Package com.solace.serdes.common
Class AbstractDeserializer<T,S>
- java.lang.Object
-
- com.solace.serdes.common.AbstractDeserializer<T,S>
-
- Type Parameters:
T
- The type of object this deserializer produces.S
- The type of schema used for deserialization.
- All Implemented Interfaces:
com.solace.serdes.Deserializer<T>
,Closeable
,AutoCloseable
- Direct Known Subclasses:
JsonSchemaDeserializer
public abstract class AbstractDeserializer<T,S> extends Object implements com.solace.serdes.Deserializer<T>
Abstract base class for deserializers that convert byte arrays into objects of type T. This class implements theDeserializer
interface and provides a common structure for schema-based deserialization.
Note: A Vertx connection will be made when configuring thisDeserializer
. Vertx threads are non-daemon and will prevent JVM exit, so always remember to callDeserializer.close()
.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes thisDeserializer
and any open Vertx connections.void
configure(Map<String,?> properties)
Configures the deserializer with the given properties.T
deserialize(String destinationName, byte[] payload)
Deserializes the given payload into an object of type T.T
deserialize(String destinationName, byte[] payload, Map<String,Object> headers)
Deserializes the given payload into an object of type T, using additional headers if provided.
-
-
-
Method Detail
-
configure
public void configure(Map<String,?> properties)
Configures the deserializer with the given properties. Properties are defined inSerdeProperties
Note: A Vertx connection will be made when configuring thisDeserializer
. Vertx threads are non-daemon and will prevent JVM exit, so always remember to callDeserializer.close()
.- Specified by:
configure
in interfacecom.solace.serdes.Deserializer<T>
- Parameters:
properties
- A Map containing configuration properties.- See Also:
SerdeProperties
-
deserialize
public T deserialize(String destinationName, byte[] payload)
Deserializes the given payload into an object of type T.Note: Unless the concrete class Deserializer (eg, Avro or JsonSchema) supports decoding the schema ID without headers, the schema identifier will fail to be decoded and the schema will not be resolved. In that case use
deserialize(String, byte[], Map)
instead where the schema ID is provided in the headers.- Specified by:
deserialize
in interfacecom.solace.serdes.Deserializer<T>
- Parameters:
destinationName
- The name of the destination.payload
- The byte array containing the serialized data.- Returns:
- The deserialized object of type T.
-
deserialize
public T deserialize(String destinationName, byte[] payload, Map<String,Object> headers)
Deserializes the given payload into an object of type T, using additional headers if provided.- Specified by:
deserialize
in interfacecom.solace.serdes.Deserializer<T>
- Parameters:
destinationName
- The name of the destination.payload
- The byte array containing the serialized data.headers
- A Map of header properties that can be used during deserialization (can be null).- Returns:
- The deserialized object of type T.
-
close
public void close()
Closes thisDeserializer
and any open Vertx connections. This method can be called multiple times without adverse effects. Once closed, attempts to deserialize will result in aSerializationException
. The deserializer can be reconfigured and reused after closing.
Note:- Vertx threads are non-daemon and will prevent JVM exit, so always remember to call
Deserializer.close()
- This method is idempotent and can be called multiple times safely
- It can be called even if the deserializer hasn't been configured
- This method is not thread-safe while
Deserializer.deserialize(String, byte[], Map)
is being called
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfacecom.solace.serdes.Deserializer<T>
- Vertx threads are non-daemon and will prevent JVM exit, so always remember to call
-
-