Package io.temporal.common.converter
Class DefaultDataConverter
- java.lang.Object
-
- io.temporal.common.converter.DefaultDataConverter
-
- All Implemented Interfaces:
DataConverter
public class DefaultDataConverter extends java.lang.Object implements DataConverter
DataConverter that delegates conversion to type specific PayloadConverter instance.
-
-
Constructor Summary
Constructors Constructor Description DefaultDataConverter(PayloadConverter... converters)
Creates instance from ordered array of converters.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <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> parameterType, java.lang.reflect.Type genericParameterType)
Implements conversion of an array of values of different types.static DefaultDataConverter
newDefaultInstance()
Creates a new instance ofDefaultDataConverter
populated with the default list of payload converters.static void
setDefaultDataConverter(DataConverter converter)
Override the global data converter default.<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)
When values is empty or is null then return empty blob.DefaultDataConverter
withPayloadConverterOverrides(PayloadConverter... overrideConverters)
Modifies thisDefaultDataConverter
by overriding some of itsPayloadConverter
s.
-
-
-
Constructor Detail
-
DefaultDataConverter
public DefaultDataConverter(PayloadConverter... converters)
Creates instance from ordered array of converters. When converting an object to payload the array of converters is iterated from the beginning until one of the converters successfully converts the value.
-
-
Method Detail
-
setDefaultDataConverter
public static void setDefaultDataConverter(DataConverter converter)
Override the global data converter default. Consider overriding data converter per client instance (usingWorkflowClientOptions.Builder.setDataConverter(DataConverter)
to avoid potential conflicts.
-
newDefaultInstance
public static DefaultDataConverter newDefaultInstance()
Creates a new instance ofDefaultDataConverter
populated with the default list of payload converters.
-
withPayloadConverterOverrides
public DefaultDataConverter withPayloadConverterOverrides(PayloadConverter... overrideConverters)
Modifies thisDefaultDataConverter
by overriding some of itsPayloadConverter
s. Every payload converter fromoverrideConverters
either replaces existing payload converter with the same encoding type, or is added to the end of payload converters list.
-
toPayload
public <T> java.util.Optional<io.temporal.api.common.v1.Payload> toPayload(T value)
- Specified by:
toPayload
in interfaceDataConverter
-
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
When values is empty or is null then return empty blob. If a single value do not wrap it into Json array. Exception stack traces are converted to a single string stack trace to save space and make them more readable.- Specified by:
toPayloads
in interfaceDataConverter
- Parameters:
values
- Java values to convert to String.- Returns:
- serialized values
- 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> parameterType, java.lang.reflect.Type genericParameterType) 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.parameterType
- type of the value stored in the contentgenericParameterType
- 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.
-
-