Class DelegatingPersistentSerializer<T extends PersistentData,S extends com.google.protobuf.Message>
java.lang.Object
com.inductiveautomation.ignition.gateway.storeforward.serialization.DelegatingPersistentSerializer<T,S>
- Type Parameters:
T
- the type of persistent dataS
- the type of proto message that relates to T
- All Implemented Interfaces:
PersistentSerializer<T,
S>
public class DelegatingPersistentSerializer<T extends PersistentData,S extends com.google.protobuf.Message>
extends Object
implements PersistentSerializer<T,S>
A delegating persistent serializer that uses a map of flavors to serialize and deserialize
PersistentData
-
Constructor Summary
ConstructorsConstructorDescriptionDelegatingPersistentSerializer
(Class<T> type, PersistentFlavor<? extends T>... flavors) Constructs a delegating persistent serializer with the given type and flavors. -
Method Summary
Modifier and TypeMethodDescriptionfromBytes
(byte[] bytes, DeserializationContext context) Deserializes the given byte array into a TPersistentData
object.fromJson
(String json, DeserializationContext context) Deserializes the given JSON string into a TPersistentData
object.fromJsonElement
(com.inductiveautomation.ignition.common.gson.JsonElement jsonElement, DeserializationContext context) Deserializes the givenJsonElement
into a TPersistentData
object.fromProtoMessage
(S message, DeserializationContext context) Deserializes the given ProtobufMessage
into a TPersistentData
object.The TPersistentData
class that is compatible with this serializer.byte[]
toBytes
(T data, SerializationContext context) Serializes the given TPersistentData
into a byte array.toJson
(T data, SerializationContext context) Serializes the given TPersistentData
into a JSON string.com.inductiveautomation.ignition.common.gson.JsonElement
toJsonElement
(T data, SerializationContext context) Serializes the given TPersistentData
into aJsonElement
.toProtoMessage
(T data, SerializationContext context) Serializes the given TPersistentData
into a ProtobufMessage
.
-
Constructor Details
-
DelegatingPersistentSerializer
@SafeVarargs public DelegatingPersistentSerializer(Class<T> type, PersistentFlavor<? extends T>... flavors) Constructs a delegating persistent serializer with the given type and flavors.- Parameters:
type
- the type of persistent data to be serialized and deserializedflavors
- the flavors to use for serialization and deserialization
-
-
Method Details
-
toBytes
Description copied from interface:PersistentSerializer
Serializes the given TPersistentData
into a byte array.- Specified by:
toBytes
in interfacePersistentSerializer<T extends PersistentData,
S extends com.google.protobuf.Message> - Parameters:
data
- The TPersistentData
to serialize.context
- The serialization context to use for serialization.- Returns:
- The serialized data as a byte array.
- Throws:
SerializeException
- If an error occurs during serialization.
-
toJson
Description copied from interface:PersistentSerializer
Serializes the given TPersistentData
into a JSON string.- Specified by:
toJson
in interfacePersistentSerializer<T extends PersistentData,
S extends com.google.protobuf.Message> - Parameters:
data
- The TPersistentData
to serialize.context
- The serialization context to use for serialization.- Returns:
- The serialized data as a JSON string.
- Throws:
SerializeException
- If an error occurs during serialization.
-
toJsonElement
public com.inductiveautomation.ignition.common.gson.JsonElement toJsonElement(T data, @Nullable SerializationContext context) throws SerializeException Description copied from interface:PersistentSerializer
Serializes the given TPersistentData
into aJsonElement
.- Specified by:
toJsonElement
in interfacePersistentSerializer<T extends PersistentData,
S extends com.google.protobuf.Message> - Parameters:
data
- The TPersistentData
to serialize.context
- The serialization context to use for serialization.- Returns:
- The serialized data as a
JsonElement
. - Throws:
SerializeException
- If an error occurs during serialization.
-
toProtoMessage
Description copied from interface:PersistentSerializer
Serializes the given TPersistentData
into a ProtobufMessage
.- Specified by:
toProtoMessage
in interfacePersistentSerializer<T extends PersistentData,
S extends com.google.protobuf.Message> - Parameters:
data
- The TPersistentData
to serialize.context
- The serialization context to use for serialization.- Returns:
- The serialized data as an S
Message
. - Throws:
SerializeException
- If an error occurs during serialization.
-
fromBytes
public T fromBytes(byte[] bytes, @Nullable DeserializationContext context) throws DeserializeException Description copied from interface:PersistentSerializer
Deserializes the given byte array into a TPersistentData
object.- Specified by:
fromBytes
in interfacePersistentSerializer<T extends PersistentData,
S extends com.google.protobuf.Message> - Parameters:
bytes
- The byte array to deserialize.context
- The deserialization context to use for deserialization.- Returns:
- The deserialized persistent data object.
- Throws:
DeserializeException
- If an error occurs during deserialization.
-
fromJson
public T fromJson(String json, @Nullable DeserializationContext context) throws DeserializeException Description copied from interface:PersistentSerializer
Deserializes the given JSON string into a TPersistentData
object.- Specified by:
fromJson
in interfacePersistentSerializer<T extends PersistentData,
S extends com.google.protobuf.Message> - Parameters:
json
- The JSON string to deserialize.context
- The deserialization context to use for deserialization.- Returns:
- The deserialized persistent data object.
- Throws:
DeserializeException
- If an error occurs during deserialization.
-
fromJsonElement
public T fromJsonElement(com.inductiveautomation.ignition.common.gson.JsonElement jsonElement, @Nullable DeserializationContext context) throws DeserializeException Description copied from interface:PersistentSerializer
Deserializes the givenJsonElement
into a TPersistentData
object.- Specified by:
fromJsonElement
in interfacePersistentSerializer<T extends PersistentData,
S extends com.google.protobuf.Message> - Parameters:
jsonElement
- TheJsonElement
to deserialize.context
- The deserialization context to use for deserialization.- Returns:
- The deserialized persistent data object.
- Throws:
DeserializeException
- If an error occurs during deserialization.
-
fromProtoMessage
public T fromProtoMessage(S message, @Nullable DeserializationContext context) throws DeserializeException Description copied from interface:PersistentSerializer
Deserializes the given ProtobufMessage
into a TPersistentData
object.- Specified by:
fromProtoMessage
in interfacePersistentSerializer<T extends PersistentData,
S extends com.google.protobuf.Message> - Parameters:
message
- The S ProtobufMessage
to deserialize.context
- The deserialization context to use for deserialization.- Returns:
- The deserialized persistent data object.
- Throws:
DeserializeException
- If an error occurs during deserialization.
-
getCompatibleClass
Description copied from interface:PersistentSerializer
The TPersistentData
class that is compatible with this serializer.- Specified by:
getCompatibleClass
in interfacePersistentSerializer<T extends PersistentData,
S extends com.google.protobuf.Message> - Returns:
- The T
PersistentData
class.
-