T - the type that represents the actual JSON document at the specified
JsonProviderpublic class JsonMerger<T> extends Object
The operation is provider-agnostic and relies on a specialized JsonProvider
which must be specified via constructor.
The resulting JSON document from the merge operation shall contain all exclusive objects from source documents. And in case of key collision (i.e., the same key appears in both documents), the following rules will be applied:
JsonMergeOption is provided specifically for that array path;
Note: The first JSON document passed is always considered to have higher
precedence than the second one in merge(T, T).
For advanced merge options, refer to JsonMergeOption.
JsonProvider,
JsonMergeOption| Constructor and Description |
|---|
JsonMerger(Class<T> jsonObjectType)
Creates a new JSON Merger for a specific JSON object type.
|
JsonMerger(JsonProvider<T> jsonProvider)
Creates a new JSON Merger for a specific provider.
|
| Modifier and Type | Method and Description |
|---|---|
T |
merge(String json1,
String json2,
JsonMergeOption... mergeOptions)
Decodes the specified JSON strings and then combines them.
|
T |
merge(T json1,
T json2,
JsonMergeOption... mergeOptions)
Combines two JSON documents.
|
public JsonMerger(JsonProvider<T> jsonProvider)
jsonProvider - the JsonProvider to use; not nullNullPointerException - if the specified JsonProvider is nullpublic JsonMerger(Class<T> jsonObjectType)
For example:
JSONObject.class for json-smartJsonObject.class for GsonJsonNode.class for JacksonjsonObjectType - the class that represents a JSON document on a
JsonProvider; not nullNullPointerException - if the specified jsonObjectType is nullIllegalArgumentException - if no JsonProvider found for the specified
jsonObjectTypepublic T merge(T json1, T json2, JsonMergeOption... mergeOptions)
json1 - the first JSON document; this object will have higher precedence
than the other one in case of key collisionjson2 - the second JSON document (lower precedence object)mergeOptions - an array of options on how to merge the documents (optional)json1 and json2public T merge(String json1, String json2, JsonMergeOption... mergeOptions)
json1 - the first JSON document; this object will have higher precedence
than the other one in case of key collisionjson2 - the second JSON document (lower precedence object)mergeOptions - an array of options on how to merge the documents (optional)json1 and json2NullPointerException - if one of the specified strings is nullJsonParseException - if one of the the specified strings is an invalid JSONCopyright © 2025. All rights reserved.