Class GsonUtils

java.lang.Object
org.aksw.commons.util.gson.GsonUtils

public class GsonUtils extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static com.google.gson.JsonElement
    copyOrNull(com.google.gson.JsonElement elt)
    Returns null if the argument is null, otherwise a deep copy.
    static boolean
    isNull(com.google.gson.JsonElement elt)
    Returns true if the argument is either java null or json null.
    static com.google.gson.JsonObject
    makePath(com.google.gson.JsonObject obj, String... keys)
    Creates fresh empty JSON objects if a key has no value
    static com.google.gson.JsonObject
    makePath(com.google.gson.JsonObject obj, List<String> keys)
     
    static com.google.gson.JsonArray
    merge(com.google.gson.JsonArray a, com.google.gson.JsonArray b)
     
    static com.google.gson.JsonElement
    merge(com.google.gson.JsonElement a, com.google.gson.JsonElement b)
     
    static com.google.gson.JsonElement
    merge(com.google.gson.JsonObject a, com.google.gson.JsonObject b)
     
    static List<String>
    This method is a stub.
    static com.google.gson.JsonObject
    setElement(com.google.gson.JsonObject obj, List<String> keys, com.google.gson.JsonElement value)
    Set an element at a given path.
    static com.google.gson.JsonObject
    setNumber(com.google.gson.JsonObject obj, List<String> keys, Number number)
     
    static com.google.gson.JsonObject
    setString(com.google.gson.JsonObject obj, List<String> keys, String value)
    Set a string at a given path.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • GsonUtils

      public GsonUtils()
  • Method Details

    • setString

      public static com.google.gson.JsonObject setString(com.google.gson.JsonObject obj, List<String> keys, String value)
      Set a string at a given path. Creates intermediate json objects as needed. A null value creates the path but removes the last key.
    • setNumber

      public static com.google.gson.JsonObject setNumber(com.google.gson.JsonObject obj, List<String> keys, Number number)
    • setElement

      public static com.google.gson.JsonObject setElement(com.google.gson.JsonObject obj, List<String> keys, com.google.gson.JsonElement value)
      Set an element at a given path. Creates intermediate json objects as needed. A null value creates the path but removes the last key.
    • makePath

      public static com.google.gson.JsonObject makePath(com.google.gson.JsonObject obj, String... keys)
      Creates fresh empty JSON objects if a key has no value
    • makePath

      public static com.google.gson.JsonObject makePath(com.google.gson.JsonObject obj, List<String> keys)
    • parsePathSegments

      public static List<String> parsePathSegments(String str)
      This method is a stub. Currently it only splits by '.'. It should later also support array access syntax such as foo.bar["baz"]
    • merge

      public static com.google.gson.JsonElement merge(com.google.gson.JsonElement a, com.google.gson.JsonElement b)
    • merge

      public static com.google.gson.JsonElement merge(com.google.gson.JsonObject a, com.google.gson.JsonObject b)
    • merge

      public static com.google.gson.JsonArray merge(com.google.gson.JsonArray a, com.google.gson.JsonArray b)
    • isNull

      public static boolean isNull(com.google.gson.JsonElement elt)
      Returns true if the argument is either java null or json null.
    • copyOrNull

      public static com.google.gson.JsonElement copyOrNull(com.google.gson.JsonElement elt)
      Returns null if the argument is null, otherwise a deep copy.