Package io.temporal.common.converter
Class GsonJsonPayloadConverter
- java.lang.Object
-
- io.temporal.common.converter.GsonJsonPayloadConverter
-
- All Implemented Interfaces:
PayloadConverter
public final class GsonJsonPayloadConverter extends java.lang.Object implements PayloadConverter
Implements conversion through GSON JSON processor. To extend useGsonJsonPayloadConverter(Function)
constructor.
-
-
Constructor Summary
Constructors Constructor Description GsonJsonPayloadConverter()
GsonJsonPayloadConverter(java.util.function.Function<com.google.gson.GsonBuilder,com.google.gson.GsonBuilder> builderInterceptor)
Constructs an instance giving an ability to overrideGson
initialization.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> T
fromData(io.temporal.api.common.v1.Payload content, java.lang.Class<T> valueClass, java.lang.reflect.Type valueType)
Implements conversion of a single value.java.lang.String
getEncodingType()
EachPayloadConverter
has an Encoding Type that it handles.static PayloadConverter
getInstance()
java.util.Optional<io.temporal.api.common.v1.Payload>
toData(java.lang.Object value)
Return empty if value is null.-
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.PayloadConverter
withContext
-
-
-
-
Constructor Detail
-
GsonJsonPayloadConverter
public GsonJsonPayloadConverter()
-
GsonJsonPayloadConverter
public GsonJsonPayloadConverter(java.util.function.Function<com.google.gson.GsonBuilder,com.google.gson.GsonBuilder> builderInterceptor)
Constructs an instance giving an ability to overrideGson
initialization.- Parameters:
builderInterceptor
- function that interceptsGsonBuilder
construction.
-
-
Method Detail
-
getInstance
public static PayloadConverter getInstance()
-
getEncodingType
public java.lang.String getEncodingType()
Description copied from interface:PayloadConverter
EachPayloadConverter
has an Encoding Type that it handles. EachPayloadConverter
should add the information about its Encoding Type into thePayload
it produces insidePayloadConverter.toData(Object)
by associating it with theEncodingKeys.METADATA_ENCODING_KEY
key attached to thePayload
's Metadata usingPayload.Builder.putMetadata(String, ByteString)
.- Specified by:
getEncodingType
in interfacePayloadConverter
- Returns:
- encoding type that this converter handles.
-
toData
public java.util.Optional<io.temporal.api.common.v1.Payload> toData(java.lang.Object value) throws DataConverterException
Return empty if value is null. Exception stack traces are converted to a single string stack trace to save space and make them more readable.- Specified by:
toData
in interfacePayloadConverter
- 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:
getEncodingType javadoc for an important implementation detail
-
fromData
public <T> T fromData(io.temporal.api.common.v1.Payload content, java.lang.Class<T> valueClass, java.lang.reflect.Type valueType) throws DataConverterException
Description copied from interface:PayloadConverter
Implements conversion of a single value.- Specified by:
fromData
in interfacePayloadConverter
- Parameters:
content
- Serialized value to convert to a Java object.valueClass
- type of the value stored in thecontent
valueType
- 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.
-
-