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.ObjectADataConverterthat delegates payload conversion to type specificPayloadConverterinstances, and delegates failure conversions to aFailureConverter.
-
-
Field Summary
Fields Modifier and Type Field Description static DataConverterSTANDARD_INSTANCEDefault data converter that is used for all objects if not overridden byWorkflowClientOptions.Builder.setDataConverter(DataConverter)orGlobalDataConverter.register(DataConverter)(less preferred).static PayloadConverter[]STANDARD_PAYLOAD_CONVERTERS
-
Constructor Summary
Constructors Constructor Description DefaultDataConverter(PayloadConverter... converters)Creates instance from ordered array of converters and a default failure converter.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description io.temporal.api.failure.v1.FailureexceptionToFailure(java.lang.Throwable throwable)Serialize an existing Throwable object into a Failure object.java.lang.RuntimeExceptionfailureToException(io.temporal.api.failure.v1.Failure failure)Instantiate an appropriate Java Exception from a serialized Failure object.<T> TfromPayload(io.temporal.api.common.v1.Payload payload, java.lang.Class<T> valueClass, java.lang.reflect.Type valueType)<T> TfromPayloads(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 a singlePayloadfrom the serializedPayloads.static DefaultDataConverternewDefaultInstance()Creates a new instance ofDefaultDataConverterpopulated with the default list of payload converters and a default failure converter.static voidsetDefaultDataConverter(DataConverter converter)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.DataConverterwithContext(SerializationContext context)A correct implementation of this interface should have a fully functional "contextless" implementation.DefaultDataConverterwithFailureConverter(FailureConverter failureConverter)Modifies thisDefaultDataConverterby overriding itsFailureConverter.DefaultDataConverterwithPayloadConverterOverrides(PayloadConverter... overrideConverters)Modifies thisDefaultDataConverterby overriding some of itsPayloadConverters.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.temporal.common.converter.DataConverter
fromPayloads
-
-
-
-
Field Detail
-
STANDARD_PAYLOAD_CONVERTERS
public static final PayloadConverter[] STANDARD_PAYLOAD_CONVERTERS
-
STANDARD_INSTANCE
public static final DataConverter STANDARD_INSTANCE
Default data converter that is used for all objects if not overridden byWorkflowClientOptions.Builder.setDataConverter(DataConverter)orGlobalDataConverter.register(DataConverter)(less preferred).This data converter is also always used (regardless of whether or not users have supplied their own converter) to perform serialization of values essential for functionality of Temporal SDK, Server, Temporal CLI or WebUI:
- Local Activity, Version, MutableSideEffect Markers metadata like id, time, name
- Search attribute values
- Stacktrace query return value
-
-
Constructor Detail
-
DefaultDataConverter
public DefaultDataConverter(PayloadConverter... converters)
Creates instance from ordered array of converters and a default failure converter. 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)
Deprecated.
-
newDefaultInstance
public static DefaultDataConverter newDefaultInstance()
Creates a new instance ofDefaultDataConverterpopulated with the default list of payload converters and a default failure converter.
-
withPayloadConverterOverrides
public DefaultDataConverter withPayloadConverterOverrides(PayloadConverter... overrideConverters)
Modifies thisDefaultDataConverterby overriding some of itsPayloadConverters. Every payload converter fromoverrideConverterseither replaces existing payload converter with the same encoding type, or is added to the end of payload converters list.
-
withFailureConverter
@Nonnull public DefaultDataConverter withFailureConverter(@Nonnull FailureConverter failureConverter)
Modifies thisDefaultDataConverterby overriding itsFailureConverter.WARNING: Most users should _never_ need to override the default failure converter. To encrypt the content of failures, see
CodecDataConverterinstead.- Parameters:
failureConverter- The failure converter to use- Throws:
java.lang.NullPointerException- if failureConverter is null
-
toPayload
public <T> java.util.Optional<io.temporal.api.common.v1.Payload> toPayload(T value) throws DataConverterException- Specified by:
toPayloadin interfaceDataConverter- Parameters:
value- value to convert- Returns:
- a
Payloadwhich 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
public <T> T fromPayload(io.temporal.api.common.v1.Payload payload, java.lang.Class<T> valueClass, java.lang.reflect.Type valueType) throws DataConverterException- Specified by:
fromPayloadin interfaceDataConverter- Throws:
DataConverterException
-
toPayloads
public java.util.Optional<io.temporal.api.common.v1.Payloads> toPayloads(java.lang.Object... values) throws DataConverterExceptionDescription copied from interface:DataConverterImplements conversion of a list of values.- Specified by:
toPayloadsin 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> parameterType, java.lang.reflect.Type genericParameterType) throws DataConverterExceptionDescription copied from interface:DataConverterImplements conversion of a singlePayloadfrom the serializedPayloads.- Specified by:
fromPayloadsin interfaceDataConverter- Parameters:
index- index of the value in the payloadscontent- serialized value to convert to Java objects.parameterType- type of the value stored in thecontentgenericParameterType- generic type of the value stored in thecontent- Returns:
- converted Java object
- Throws:
DataConverterException- if conversion of the data passed as parameter failed for any reason.
-
failureToException
@Nonnull public java.lang.RuntimeException failureToException(@Nonnull io.temporal.api.failure.v1.Failure failure)Description copied from interface:DataConverterInstantiate an appropriate Java Exception from a serialized Failure object. The default implementation delegates the conversion process to an instance ofFailureConverter, using this data converter for payload decoding.- Specified by:
failureToExceptionin interfaceDataConverter- Parameters:
failure- Failure protobuf object to deserialize into an exception
-
exceptionToFailure
@Nonnull public io.temporal.api.failure.v1.Failure exceptionToFailure(@Nonnull java.lang.Throwable throwable)Description copied from interface:DataConverterSerialize an existing Throwable object into a Failure object. The default implementation delegates the conversion process to an instance ofFailureConverter, using this data converter for payload encoding.- Specified by:
exceptionToFailurein interfaceDataConverter- Parameters:
throwable- a Throwable object to serialize into a Failure protobuf object
-
withContext
@Nonnull public DataConverter withContext(@Nonnull SerializationContext context)
Description copied from interface:DataConverterA correct implementation of this interface should have a fully functional "contextless" implementation. Temporal SDK will call this method when a knowledge of the context exists, butDataConvertercan be used directly by user code and sometimes SDK itself without any context.Note: this method is expected to be cheap and fast. Temporal SDK doesn't always cache the instances and may be calling this method very often. Users are responsible to make sure that this method doesn't recreate expensive objects like Jackson's
ObjectMapperon every call.- Specified by:
withContextin interfaceDataConverter- Parameters:
context- provides information to the data converter about the abstraction the data belongs to- Returns:
- an instance of DataConverter that may use the provided
contextfor serialization - See Also:
SerializationContext
-
-