Class JSONMergeUtils


  • public class JSONMergeUtils
    extends Object
    This utility class contains various methods related to merging and manipulating JSON elements.
    • Constructor Detail

      • JSONMergeUtils

        public JSONMergeUtils()
    • Method Detail

      • extendJSONObject

        public static void extendJSONObject​(com.google.gson.JsonObject destinationObject,
                                            JSONMergeUtils.ConflictStrategy conflictResolutionStrategy,
                                            com.google.gson.JsonObject... jsonObjects)
                                     throws JSONObjectExtensionException
        Extends a particular JSON Object by merging multiple objects under a given conflict resolution strategy.
        Parameters:
        destinationObject - Destination JSON Object.
        conflictResolutionStrategy - Conflict resolution strategy.
        jsonObjects - JSON Objects to be merged.
        Throws:
        JSONObjectExtensionException
      • extendJSONObject

        public static com.google.gson.JsonObject extendJSONObject​(com.google.gson.JsonObject sourceObj,
                                                                  com.google.gson.JsonObject targetObj)
        Merges a source JSON object into a target JSON object. 1. If fields have equal names, merge recursively. 2. Null values in source will remove the field from the target. 3. Override target values with source values 4. Keys not supplied in source will remain unchanged in target
        Parameters:
        sourceObj - Source JSON Object.
        targetObj - Target JSON Object.
        Returns:
        Target JSON Object.
        Throws:
        UnsupportedOperationException
      • getJsonObject

        public static com.google.gson.JsonObject getJsonObject​(String jsonString)
        Creates a JSON object from a string.
        Parameters:
        jsonString - JSON object as a string.
        Returns:
        JSON Object
      • getJsonArray

        public static com.google.gson.JsonArray getJsonArray​(String jsonString)
        Convert a string to JSON Array.
        Parameters:
        jsonString - JSON array as string.
        Returns:
        JSON array.
      • count

        public static int count​(com.google.gson.JsonArray array,
                                com.google.gson.JsonElement element)
        Count given elements in array.
        Parameters:
        element - Element to find.
        Returns:
        Amount of given elements in array.