Package org.hobbit.core.rabbit
Class GsonUtils
java.lang.Object
org.hobbit.core.rabbit.GsonUtils
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TdeserializeObjectWithGson(com.google.gson.Gson gson, byte[] data, Class<? extends T> clazz) Deserialize a Java data object that was received as JSON with a command.static <T> byte[]serializeObjectWithGson(com.google.gson.Gson gson, T object) Serialize a Java object as JSON using the givenGsoninstance and theRabbitMQUtilsclass.
-
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 givenGsoninstance and theRabbitMQUtilsclass.- Type Parameters:
T- The class of the given object- Parameters:
gson- The Gson instance used for the serialization as JSONobject- 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 theRabbitMQUtilsclass, before it will be deserialized using the givenGsonobject.- 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
-