Class DefaultDataConverter

  • All Implemented Interfaces:
    DataConverter

    public class DefaultDataConverter
    extends java.lang.Object
    implements DataConverter
    DataConverter that delegates conversion to type specific PayloadConverter instance.
    • 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 by WorkflowClientOptions.Builder.setDataConverter(DataConverter) or GlobalDataConverter.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, tctl 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. 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

      • newDefaultInstance

        public static DefaultDataConverter newDefaultInstance()
        Creates a new instance of DefaultDataConverter populated with the default list of payload converters.
      • withPayloadConverterOverrides

        public DefaultDataConverter withPayloadConverterOverrides​(PayloadConverter... overrideConverters)
        Modifies this DefaultDataConverter by overriding some of its PayloadConverters. Every payload converter from overrideConverters 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)
                                                                            throws DataConverterException
        Specified by:
        toPayload in interface DataConverter
        Parameters:
        value - value to convert
        Returns:
        a Payload which is a protobuf message containing byte-array serialized representation of value. Optional here is for legacy and backward compatibility reasons. This Optional is expected to always be filled.
        Throws:
        DataConverterException - if conversion fails
      • 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 interface DataConverter
        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 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 interface DataConverter
        Parameters:
        index - index of the value in the payloads
        content - serialized value to convert to Java objects.
        parameterType - type of the value stored in the content
        genericParameterType - 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.