Class JsonDataConverter

  • All Implemented Interfaces:
    DataConverter

    public final class JsonDataConverter
    extends java.lang.Object
    implements DataConverter
    Implements conversion through GSON JSON processor. To extend use JsonDataConverter(Function) constructor. Thrift structures are converted using TJSONProtocol. 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 override Gson 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 override Gson initialization.
        Parameters:
        builderInterceptor - function that intercepts GsonBuilder construction.
    • Method Detail

      • 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 interface DataConverter
        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 interface DataConverter
        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 interface DataConverter
        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.