public class GenericJSONConfigurationMerger<T> extends AbstractConfigurationMerger<T>
ConfigurationMerger that combines two Configuration objects
of type JSON.
The operation is provider-agnostic and depends 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 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
GenericJSONConfigurationMerger(JsonProvider, Map).
JsonProvider,
ConfigurationMerger| Constructor and Description |
|---|
GenericJSONConfigurationMerger(JsonProvider jsonProvider)
Creates a new JSON Configuration Merger for a specific provider.
|
GenericJSONConfigurationMerger(JsonProvider jsonProvider,
Map<String,String> distinctObjectKeysInsideArrays)
Creates a new JSON Configuration Merger for a specific provider and a preset map of
distinct keys.
|
public GenericJSONConfigurationMerger(JsonProvider jsonProvider)
jsonProvider - the JsonProvider to use; not nullNullPointerException - if the specified JsonProvider is nullpublic GenericJSONConfigurationMerger(JsonProvider jsonProvider, Map<String,String> distinctObjectKeysInsideArrays)
The distinctObjectKeysInsideArrays map shall be used to specify key objects
inside arrays.
For example, consider the following document:
{
"params": [
{
"param": "name",
"value": "John Doe"
},
{
"param": "age",
"value": 33
}
]
}
A map 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.
jsonProvider - the JsonProvider to use; not nulldistinctObjectKeysInsideArrays - a map that associates JsonPath expressions and
distinct keys during the merge of an array;
null is allowedNullPointerException - if the specified JsonProvider is nullIllegalArgumentException - if the map contains a null or empty expressioncom.jayway.jsonpath.InvalidPathException - if the specified JsonPath expression is invalidCopyright © 2022. All rights reserved.