Class GsonUtils

java.lang.Object
org.hobbit.core.rabbit.GsonUtils

public class GsonUtils extends Object
A class that offers simple utility methods that hide some steps that are necessary to transform java objects into JSON containing byte arrays and vice versa.
Author:
Michael Röder (michael.roeder@uni-paderborn.de)
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
  • Constructor Details

    • GsonUtils

      public GsonUtils()
  • Method Details

    • serializeObjectWithGson

      public static <T> byte[] serializeObjectWithGson(com.google.gson.Gson gson, T object)
      Serialize a Java object as JSON using the given Gson instance and the RabbitMQUtils class.
      Type Parameters:
      T - The class of the given object
      Parameters:
      gson - The Gson instance used for the serialization as JSON
      object - The object that should be serialized
      Returns:
      The serialized object as JSON in a byte representation or null if the given object was null
    • deserializeObjectWithGson

      public static <T> T deserializeObjectWithGson(com.google.gson.Gson gson, byte[] data, Class<? extends T> clazz)
      Deserialize a Java data object that was received as JSON with a command. First, the given byte array will be transformed into a String using the RabbitMQUtils class, before it will be deserialized using the given Gson object.
      Type Parameters:
      T - The class that the data object should have.
      Parameters:
      gson - The Gson instance used to deserialize the JSON object.
      data - The byte array that has been received.
      clazz - The class that the data object should have.
      Returns:
      The deserialized object or null if an error occurred