Class JsonObjectUtil


  • public class JsonObjectUtil
    extends Object
    Provide convenience methods to help use GSON JsonObjects similar to the deprecated JSONObject in Sling Json.
    • Method Detail

      • toJsonObject

        public static com.google.gson.JsonObject toJsonObject​(String json)
      • toJsonObject

        public static com.google.gson.JsonObject toJsonObject​(org.apache.sling.api.resource.Resource resource)
      • toJsonObject

        public static com.google.gson.JsonObject toJsonObject​(Object source)
      • toJsonObject

        public static <T> com.google.gson.JsonObject toJsonObject​(T source,
                                                                  int depth)
      • pruneToDepth

        public static void pruneToDepth​(com.google.gson.JsonObject obj,
                                        int depth)
      • getAsJsonString

        public static <T> String getAsJsonString​(T source,
                                                 int depth)
      • isSingularElement

        public static boolean isSingularElement​(com.google.gson.JsonElement elem)
      • getOptional

        public static Optional<com.google.gson.JsonElement> getOptional​(com.google.gson.JsonObject obj,
                                                                        String prop)
      • getOptionalProperty

        public static <T> T getOptionalProperty​(com.google.gson.JsonObject obj,
                                                String prop,
                                                Function<com.google.gson.JsonElement,​T> getter,
                                                T defaultValue)
      • getOptionalObject

        public static Optional<com.google.gson.JsonObject> getOptionalObject​(com.google.gson.JsonObject obj,
                                                                             String prop)
      • getString

        public static String getString​(com.google.gson.JsonObject obj,
                                       String prop,
                                       String defaultValue)
      • getString

        public static String getString​(com.google.gson.JsonObject obj,
                                       String prop)
      • getLong

        public static Long getLong​(com.google.gson.JsonObject obj,
                                   String prop,
                                   Long defaultValue)
      • getLong

        public static Long getLong​(com.google.gson.JsonObject obj,
                                   String prop)
      • getInteger

        public static Integer getInteger​(com.google.gson.JsonObject obj,
                                         String prop,
                                         Integer defaultValue)
      • getInteger

        public static Integer getInteger​(com.google.gson.JsonObject obj,
                                         String prop)
      • getBoolean

        public static Boolean getBoolean​(com.google.gson.JsonObject obj,
                                         String prop,
                                         Boolean defaultValue)
      • getBoolean

        public static Boolean getBoolean​(com.google.gson.JsonObject obj,
                                         String prop)