Class GsonUtils


  • public final class GsonUtils
    extends Object
    • Method Detail

      • setOrAppendToArray

        public static void setOrAppendToArray​(com.google.gson.JsonObject object,
                                              String propertyName,
                                              com.google.gson.JsonElement newValue)
        Sets the given newValue as the value of property propertyName on parent, wrapping it in an array if necessary.

        The behavior is as follows:

        • If there is currently no value for this property, the property is simply set to newValue using JsonObject.add(String, JsonElement).
        • If the current value of the property is an array, newValue is added to this array.
        • Otherwise, the current value is replaced by an array containing the current value followed by the newValue.
        Parameters:
        object - The object whose property must be set.
        propertyName - The name of the property to set.
        newValue - The value to set.
      • deepCopy

        public static <T> T deepCopy​(com.google.gson.Gson gson,
                                     Class<T> objectType,
                                     T object)
        Efficiently performs a deep copy of a given object using Gson serialization/deserialization.
        Type Parameters:
        T - The type of the object to copy.
        Parameters:
        gson - The Gson object.
        objectType - The type of the object to copy.
        object - The object to copy.
        Returns:
        A deep copy of object.