Package org.apache.synapse.util
Class JSONMergeUtils
- java.lang.Object
-
- org.apache.synapse.util.JSONMergeUtils
-
public class JSONMergeUtils extends Object
This utility class contains various methods related to merging and manipulating JSON elements.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
JSONMergeUtils.ConflictStrategy
-
Constructor Summary
Constructors Constructor Description JSONMergeUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
count(com.google.gson.JsonArray array, com.google.gson.JsonElement element)
Count given elements in array.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.static void
extendJSONObject(com.google.gson.JsonObject destinationObject, JSONMergeUtils.ConflictStrategy conflictResolutionStrategy, com.google.gson.JsonObject... jsonObjects)
Extends a particular JSON Object by merging multiple objects under a given conflict resolution strategy.static com.google.gson.JsonArray
getJsonArray(String jsonString)
Convert a string to JSON Array.static com.google.gson.JsonObject
getJsonObject(String jsonString)
Creates a JSON object from a string.
-
-
-
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.
-
-