Package io.temporal.common.converter
Interface DataConverter
-
- All Known Implementing Classes:
CodecDataConverter
,DefaultDataConverter
public interface DataConverter
Used by the framework to serialize/deserialize method parameters that need to be sent over the wire.Most users should never implement this interface until absolutely needed.
Instead, users should implementPayloadConverter
to customize Object <-> Payload (bytes) conversionPayloadCodec
to perform Payload (bytes) <-> Payload (bytes) encoding (like encryption or compression)
PayloadConverter
can be registered onDefaultDataConverter
instance. For that:- Obtain
DefaultDataConverter
instance fromDefaultDataConverter.newDefaultInstance()
. Register your customPayloadConverter
usingDefaultDataConverter.withPayloadConverterOverrides(PayloadConverter...)
. This way will preserve the standard set ofPayloadConverter
s supplied by Temporal JavaSDK other that the ones that were overridden. SeeDefaultDataConverter.STANDARD_PAYLOAD_CONVERTERS
) - Pass the custom
PayloadConverter
directly toDefaultDataConverter(PayloadConverter...)
to discard the standardPayloadConverter
s supplied by Temporal JavaSDK out of the box.
DataConverter
created on previous step may be bundled withPayloadCodec
s usingCodecDataConverter
or used directly if no customPayloadCodec
s are needed.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description static java.lang.Object[]
arrayFromPayloads(DataConverter converter, java.util.Optional<io.temporal.api.common.v1.Payloads> content, java.lang.Class<?>[] parameterTypes, java.lang.reflect.Type[] genericParameterTypes)
<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.static DataConverter
getDefaultInstance()
Deprecated.<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.
-
-
-
Method Detail
-
getDefaultInstance
@Deprecated static DataConverter getDefaultInstance()
Deprecated.
-
toPayload
<T> java.util.Optional<io.temporal.api.common.v1.Payload> toPayload(T value) throws DataConverterException
- 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. - Throws:
DataConverterException
- if conversion fails
-
fromPayload
<T> T fromPayload(io.temporal.api.common.v1.Payload payload, java.lang.Class<T> valueClass, java.lang.reflect.Type valueType) throws DataConverterException
- Throws:
DataConverterException
-
toPayloads
java.util.Optional<io.temporal.api.common.v1.Payloads> toPayloads(java.lang.Object... values) throws DataConverterException
Implements conversion of a list of values.- 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
<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
Implements conversion of an array of values of different types. Useful for deserializing arguments of function invocations.- 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.
-
arrayFromPayloads
static java.lang.Object[] arrayFromPayloads(DataConverter converter, java.util.Optional<io.temporal.api.common.v1.Payloads> content, java.lang.Class<?>[] parameterTypes, java.lang.reflect.Type[] genericParameterTypes) throws DataConverterException
- Throws:
DataConverterException
-
-