public class JSONObjectConfigurationMerger extends AbstractConfigurationMerger<net.minidev.json.JSONObject>
ConfigurationMerger that combines two Configuration
objects of type JSONObject (json-smart implementation) into a single one.
The resulting JSON document from the merge operation shall contain all exclusive objects from source documents and in case of In case of key collisions (i.e., the same key appears in both documents), the following rules will be applied:
Configuration will be selected;Configuration will be selected as fallback;Configuration will be selected as
fallback
A special solution for merging arrays of distinct objects with a specific key can be
created using the optional constructor JSONObjectConfigurationMerger(Map).
ConfigurationMerger| Constructor and Description |
|---|
JSONObjectConfigurationMerger()
Creates a standard
JSONObjectConfigurationMerger. |
JSONObjectConfigurationMerger(Map<String,String> distinctObjectKeysInsideArrays)
Creates a new
JSONObjectConfigurationMerger with a map of distinct keys
associated with specific JsonPath expressions. |
public JSONObjectConfigurationMerger()
JSONObjectConfigurationMerger.public JSONObjectConfigurationMerger(Map<String,String> distinctObjectKeysInsideArrays)
JSONObjectConfigurationMerger with a map of distinct keys
associated with specific JsonPath expressions.
Use the distinctObjectKeysInsideArrays map to specify how to combine arrays of
objects inside the JSON. For example, considering the following document:
{
"params": [
{
"param": "name",
"value": "John Doe"
},
{
"param": "age",
"value": 33
}
]
}
A map containing an entry with the key "$.params" associated with the
"param" value tells the algorithm to check for distinct objects identified by
the value inside the "param" field during the merge of the "$.params"
array.
In other words, if two JSON documents contain different objects identified by the same
"param" attribute inside the array returned by the JsonPath expression
"$.params", then only the object from the Configuration with the
highest precedence will be selected.
A JsonPath expression can be specified using either dot- or bracket-notation,
but complex expressions containing filters, script, subscript, or union operations, are
not supported.
distinctObjectKeysInsideArrays - a map that associates JsonPath expressions inside
the JSONObject and object keys for
distinction during the merge of an array;
null is allowedIllegalArgumentException - if the specified expression is null or emptycom.jayway.jsonpath.InvalidPathException - if the specified JsonPath expression is invalidCopyright © 2022. All rights reserved.