Interface PayloadConverter
- All Known Implementing Classes:
ByteArrayPayloadConverter,GsonJsonPayloadConverter,Jackson3JsonPayloadConverter,JacksonJsonPayloadConverter,NullPayloadConverter,ProtobufJsonPayloadConverter,ProtobufPayloadConverter
public interface PayloadConverter
Used by the framework to serialize/deserialize method parameters that need to be sent over the
wire.
PayloadConverter is expected to pass the RawValue payload through without
conversion. Though it should still apply the PayloadCodec to
the RawValue payloads.
-
Method Summary
Modifier and TypeMethodDescription<T> TImplements conversion of a single value.EachPayloadConverterhas an Encoding Type that it handles.Optional<io.temporal.api.common.v1.Payload> Implements conversion of a list of values.default PayloadConverterwithContext(SerializationContext context) A correct implementation of this interface should have a fully functional "contextless" implementation.
-
Method Details
-
getEncodingType
String getEncodingType()EachPayloadConverterhas an Encoding Type that it handles. EachPayloadConvertershould add the information about its Encoding Type into thePayloadit produces insidetoData(Object)by associating it with theEncodingKeys.METADATA_ENCODING_KEYkey attached to thePayload's Metadata usingPayload.Builder.putMetadata(String, ByteString).- Returns:
- encoding type that this converter handles.
-
toData
Implements conversion of a list of values.- Parameters:
value- Java value to convert.- Returns:
- converted value
- Throws:
DataConverterException- if conversion of the value passed as parameter failed for any reason.- See Also:
-
fromData
<T> T fromData(io.temporal.api.common.v1.Payload content, Class<T> valueType, Type valueGenericType) throws DataConverterException Implements conversion of a single value.- Parameters:
content- Serialized value to convert to a Java object.valueType- type of the value stored in thecontentvalueGenericType- 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.
-
withContext
A 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.- 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:
-