public final class JsonMergeOption extends Object
Use onPath(String) to initialize the construction of a
JsonMergeOption with a specific document path, then let the API guide you
through the additional builder methods to finalize the construction of the desired
merge option.
Examples:
JsonMergeOption.onPath("$.parameters").findObjectsIdentifiedBy("name").thenPickTheHigherPrecedenceOne();JsonMergeOption.onPath("$.files").findObjectsIdentifiedBy("id", "version").thenDoADeepMerge();JsonMergeOption.onPath("$.files").addDistinctObjectsOnly();JsonMergeOption.onPath("$.files").addAll();
| Modifier and Type | Class and Description |
|---|---|
static class |
JsonMergeOption.Builder
A builder for
JsonMergeOption, with the document path already set. |
static class |
JsonMergeOption.BuilderWithKeys
An intermediary
JsonMergeOption build stage that is applicable when one or more
distinct keys are specified for a given document path. |
| Modifier and Type | Field and Description |
|---|---|
static JsonMergeOption |
DEFAULT
The default merge option.
|
| Modifier and Type | Method and Description |
|---|---|
static JsonMergeOption |
distinctKey(String jsonPath,
String key)
Deprecated.
Use
onPath(String) instead |
static JsonMergeOption |
distinctKeys(String jsonPath,
String... keys)
Deprecated.
Use
onPath(String) instead |
boolean |
equals(Object object)
Indicates whether some other object is "equal to" this one.
|
List<String> |
getKeys()
Returns a list of keys to be considered for distinct JSON objects identification inside
the array represented by
getPath(). |
JsonPathExpression |
getPath()
Returns a
JsonPath expression that represents a specific path of the JSON
document to receive special handling during the merge |
int |
hashCode()
Returns a hash code value for the object.
|
boolean |
isDeepMerge()
Returns a flag indicating whether or not to do a deep merge of the elements inside the
document path represented by
getPath(). |
boolean |
isDistinctObjectsOnly()
Returns a flag indicating whether or not to check for duplicate objects before adding
them during the merge of the array path represented by
getPath(). |
static JsonMergeOption.Builder |
onPath(String jsonPath)
Initializes the construction of a
JsonMergeOption for the document path
determined by the given JsonPath expression. |
String |
toString()
Returns a string representation of this
JsonMergeOption. |
public static final JsonMergeOption DEFAULT
@Deprecated public static JsonMergeOption distinctKey(String jsonPath, String key)
onPath(String) insteadJsonPath expression.
For example, consider the following document:
{
"params": [
{
"param": "name",
"value": "John Doe"
},
{
"param": "age",
"value": 33
}
]
}
A MergeOption of key "param" associated with the JsonPath
expression "$.params" tells the algorithm to check for distinct objects
identified by the same 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 key inside that array, then only the object from the highest-precedence JSON document 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.
jsonPath - a JsonPath expression that identifies the array; not emptykey - the key to be considered unique for objects inside an arrayJsonMergeOption with the specified pair of distinct path and keyIllegalArgumentException - if one of the parameters is null or blankcom.jayway.jsonpath.InvalidPathException - if the specified JsonPath expression is invalid@Deprecated public static JsonMergeOption distinctKeys(String jsonPath, String... keys)
onPath(String) insteadJsonPath expression.
For example, consider the following document:
{
"files": [
{
"id": "d2b638be-40d2-4965-906e-291521f8a19d",
"version": "1",
"date": "2022-07-07T10:42:21"
},
{
"id": "d2b638be-40d2-4965-906e-291521f8a19d",
"version": "2",
"date": "2022-08-06T09:40:01"
},
{
"id": "9570cc646-1586-11ed-861d-0242ac120002",
"version": "1",
"date": "2022-08-06T09:51:40"
}
]
}
A MergeOption of keys "id" and "version" associated with the
JsonPath expression "$.files" tells the algorithm to check for distinct
objects identified by the same values in both fields "id" and "version"
during the merge of the "$.files" array.
In other words, if two JSON documents contain different objects identified by the same keys inside that array, then only the object from the highest-precedence JSON document 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.
jsonPath - a JsonPath expression that identifies the array; not emptykeys - one or more keys to be considered unique for objects inside an arrayJsonMergeOption with the specified pair of path and distinct keysIllegalArgumentException - if one of the parameters is null or blankcom.jayway.jsonpath.InvalidPathException - if the specified JsonPath expression is invalidpublic static JsonMergeOption.Builder onPath(String jsonPath)
JsonMergeOption for the document path
determined by the given JsonPath expression.
A JsonPath expression can be specified using either dot- or bracket-notation,
but complex expressions containing filters, script, subscript, or union operations, are
not fully supported.
Examples of valid expressions:
$.sites $.sites[*].users $.sites[*].users[*].preferences
$['sites'] $['sites'][*]['users'] $['sites'][*]['users'][*]['preferences']
{
"sites": [
{
"id": "europe-1",
"users": [
{
"email": "camillelawson@zolarex.com",
"preferences": [
{
"key": "theme",
"value": "light"
}
]
}
]
}
]
}
jsonPath - a JsonPath expression that identifies the document part that
should receive special handling during the merge; not emptyJsonMergeOption builder initialized with the specified
JsonPathIllegalArgumentException - if the specified expression is null or emptycom.jayway.jsonpath.InvalidPathException - if the specified JsonPath expression is
invalidJsonPathExpressionpublic JsonPathExpression getPath()
JsonPath expression that represents a specific path of the JSON
document to receive special handling during the mergeJsonPathExpression; not nullpublic List<String> getKeys()
getPath().public boolean isDeepMerge()
getPath().public boolean isDistinctObjectsOnly()
getPath().public String toString()
JsonMergeOption.public int hashCode()
Copyright © 2025. All rights reserved.