Package com.uber.cadence.converter
Class JsonDataConverter
- java.lang.Object
-
- com.uber.cadence.converter.JsonDataConverter
-
- All Implemented Interfaces:
DataConverter
public final class JsonDataConverter extends java.lang.Object implements DataConverter
Implements conversion through GSON JSON processor. To extend useJsonDataConverter(Function)
constructor. Thrift structures are converted usingTJSONProtocol
. When using thrift only one argument of a method is expected.
-
-
Constructor Summary
Constructors Constructor Description JsonDataConverter(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(byte[] content, java.lang.Class<T> valueClass, java.lang.reflect.Type valueType)
Implements conversion of a single value.java.lang.Object[]
fromDataArray(byte[] content, java.lang.reflect.Type... valueTypes)
Implements conversion of an array of values of different types.static DataConverter
getInstance()
byte[]
toData(java.lang.Object... values)
When values is empty or it contains a single value and it is null then return empty blob.
-
-
-
Constructor Detail
-
JsonDataConverter
public JsonDataConverter(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 DataConverter getInstance()
-
toData
public byte[] toData(java.lang.Object... values) throws DataConverterException
When values is empty or it contains a single value and it 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:
toData
in interfaceDataConverter
- Parameters:
values
- Java value to convert to String.- Returns:
- converted value
- Throws:
DataConverterException
- if conversion of the value passed as parameter failed for any reason.
-
fromData
public <T> T fromData(byte[] content, java.lang.Class<T> valueClass, java.lang.reflect.Type valueType) throws DataConverterException
Description copied from interface:DataConverter
Implements conversion of a single value.- Specified by:
fromData
in interfaceDataConverter
- Parameters:
content
- Serialized value to convert to a Java object.- Returns:
- converted Java object
- Throws:
DataConverterException
- if conversion of the data passed as parameter failed for any reason.
-
fromDataArray
public java.lang.Object[] fromDataArray(byte[] content, java.lang.reflect.Type... valueTypes) 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:
fromDataArray
in interfaceDataConverter
- Parameters:
content
- serialized value to convert to Java objects.- Returns:
- array of converted Java objects
- Throws:
DataConverterException
- if conversion of the data passed as parameter failed for any reason.
-
-