Package io.temporal.common.converter
Class CodecDataConverter
- java.lang.Object
-
- io.temporal.common.converter.CodecDataConverter
-
- All Implemented Interfaces:
DataConverter
,PayloadCodec
public class CodecDataConverter extends java.lang.Object implements DataConverter, PayloadCodec
A delegatingDataConverter
implementation that wraps and chains both anotherDataConverter
and severalPayloadCodec
s.The underlying
DataConverter
is expected to be responsible for conversion between user objects and bytes represented asPayloads
, while the underlying chain of codecs is responsible for a subsequent byte <-> byte manipulation such as encryption or compression
-
-
Constructor Summary
Constructors Constructor Description CodecDataConverter(DataConverter dataConverter, java.util.Collection<PayloadCodec> codecs)
When serializing to Payloads:dataConverter
is applied first, following by the chain ofcodecs
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<io.temporal.api.common.v1.Payload>
decode(java.util.List<io.temporal.api.common.v1.Payload> payloads)
java.util.List<io.temporal.api.common.v1.Payload>
encode(java.util.List<io.temporal.api.common.v1.Payload> payloads)
<T> T
fromPayload(io.temporal.api.common.v1.Payload payload, java.lang.Class<T> valueClass, java.lang.reflect.Type valueType)
<T> T
fromPayloads(int index, java.util.Optional<io.temporal.api.common.v1.Payloads> content, java.lang.Class<T> valueType, java.lang.reflect.Type valueGenericType)
Implements conversion of an array of values of different types.<T> java.util.Optional<io.temporal.api.common.v1.Payload>
toPayload(T value)
java.util.Optional<io.temporal.api.common.v1.Payloads>
toPayloads(java.lang.Object... values)
Implements conversion of a list of values.
-
-
-
Constructor Detail
-
CodecDataConverter
public CodecDataConverter(DataConverter dataConverter, java.util.Collection<PayloadCodec> codecs)
When serializing to Payloads:dataConverter
is applied first, following by the chain ofcodecs
.codecs
are applied last to first meaning the earlier encoders wrap the later ones
codecs
are applied first to last to reverse the effect following by thedataConverter
dataConverter
is applied last
- Parameters:
dataConverter
- to delegate data conversion tocodecs
- to delegate bytes encoding/decoding to. When encoding, the codecs are applied last to first meaning the earlier encoders wrap the later ones. When decoding, the decoders are applied first to last to reverse the effect
-
-
Method Detail
-
toPayload
public <T> java.util.Optional<io.temporal.api.common.v1.Payload> toPayload(T value)
- Specified by:
toPayload
in interfaceDataConverter
- Parameters:
value
- value to convert- Returns:
- a
Payload
which is a protobuf message containing byte-array serialized representation ofvalue
. Optional here is for legacy and backward compatibility reasons. This Optional is expected to always be filled.
-
fromPayload
public <T> T fromPayload(io.temporal.api.common.v1.Payload payload, java.lang.Class<T> valueClass, java.lang.reflect.Type valueType)
- Specified by:
fromPayload
in interfaceDataConverter
-
toPayloads
public java.util.Optional<io.temporal.api.common.v1.Payloads> toPayloads(java.lang.Object... values) throws DataConverterException
Description copied from interface:DataConverter
Implements conversion of a list of values.- Specified by:
toPayloads
in interfaceDataConverter
- Parameters:
values
- Java values to convert to String.- Returns:
- converted value. Return empty Optional if values are empty.
- Throws:
DataConverterException
- if conversion of the value passed as parameter failed for any reason.
-
fromPayloads
public <T> T fromPayloads(int index, java.util.Optional<io.temporal.api.common.v1.Payloads> content, java.lang.Class<T> valueType, java.lang.reflect.Type valueGenericType) throws DataConverterException
Description copied from interface:DataConverter
Implements conversion of an array of values of different types. Useful for deserializing arguments of function invocations.- Specified by:
fromPayloads
in interfaceDataConverter
- Parameters:
index
- index of the value in the payloadscontent
- serialized value to convert to Java objects.valueType
- type of the value stored in the contentvalueGenericType
- generic type of the value stored in the content- Returns:
- converted Java object
- Throws:
DataConverterException
- if conversion of the data passed as parameter failed for any reason.
-
encode
@Nonnull public java.util.List<io.temporal.api.common.v1.Payload> encode(@Nonnull java.util.List<io.temporal.api.common.v1.Payload> payloads)
- Specified by:
encode
in interfacePayloadCodec
-
decode
@Nonnull public java.util.List<io.temporal.api.common.v1.Payload> decode(@Nonnull java.util.List<io.temporal.api.common.v1.Payload> payloads)
- Specified by:
decode
in interfacePayloadCodec
-
-