public final class PatchOperation extends Object
Map
) or primitive (Java String
,
Boolean
, or Number
): these are considered to be
single-valued fields
List
): these are considered to be
multi-valued fields exhibiting either:
add
- ensures that the targeted field
contains the provided value(s). Missing parent fields will be created as
needed. If the targeted field is already present and it is single-valued
(i.e. not an array) then the existing value will be replaced. If the targeted
field is already present and it is multi-valued (i.e. an array) then the
behavior depends on whether the field is a list or a set:
remove
- ensures that the targeted field
does not contain the provided value(s) if present. If no values are provided
with the remove operation then the entire field will be removed if it is
present. If the remove operation targets a single-valued field and a patch
value is provided then it must match the existing value for it to be removed,
otherwise the field is left unchanged. If the remove operation targets a
multi-valued field then the behavior depends on whether the field is a
list or a set:
replace
- removes any existing value(s)
of the targeted field and replaces them with the provided value(s). A replace
operation is semantically equivalent to a remove
followed by an
add
, except that indexed updates are not permitted regardless of
whether or not the field is a list.
increment
- increments or decrements
the targeted numerical field value(s) by the specified amount. If the amount
is negative then the value(s) are decremented. It is an error to attempt to
increment a field which does not contain a number or an array of numbers. It
is also an error if the patch value is not a single value.
NOTE: this class does not define how field values will be matched, nor does it define whether a resource supports indexed based modifications, nor whether fields are single or multi-valued. Instead these matters are the responsibility of the resource provider and, in particular, the JSON schema being enforced for the targeted resource.
Modifier and Type | Field and Description |
---|---|
static String |
FIELD_FIELD
The name of the field which contains the target field in the JSON
representation.
|
static String |
FIELD_FROM
The name of the source field for copy and move operations.
|
static String |
FIELD_OPERATION
The name of the field which contains the type of patch operation in the
JSON representation.
|
static String |
FIELD_VALUE
The name of the field which contains the operation value in the JSON
representation.
|
static String |
OPERATION_ADD
The identifier used for "add" operations.
|
static String |
OPERATION_COPY
The identifier used for "copy" operations.
|
static String |
OPERATION_INCREMENT
The identifier used for "increment" operations.
|
static String |
OPERATION_MOVE
The identifier used for "move" operations.
|
static String |
OPERATION_REMOVE
The identifier used for "remove" operations.
|
static String |
OPERATION_REPLACE
The identifier used for "replace" operations.
|
static String |
OPERATION_TRANSFORM
The identifier used for "transform" operations.
|
Modifier and Type | Method and Description |
---|---|
static PatchOperation |
add(JsonPointer field,
Object value)
Creates a new "add" patch operation which will add the provided value(s)
to the specified field.
|
static PatchOperation |
add(String field,
Object value)
Creates a new "add" patch operation which will add the provided value(s)
to the specified field.
|
static PatchOperation |
copy(JsonPointer from,
JsonPointer field)
Creates a new "copy" patch operation which will copy the value found at `from` to `path`.
|
static PatchOperation |
copy(String from,
String field)
Creates a new "copy" patch operation which will copy the value found at `from` to `path`.
|
static PatchOperation |
copyOf(PatchOperation operation)
Returns a deep copy of the provided patch operation.
|
JsonPointer |
getField()
Returns the field targeted by the patch operation.
|
JsonPointer |
getFrom()
Returns the source field for move and copy operations.
|
String |
getOperation()
Returns the type of patch operation to be performed.
|
JsonValue |
getValue()
Returns the value for the patch operation.
|
static PatchOperation |
increment(JsonPointer field,
Number amount)
Creates a new "increment" patch operation which will increment the
value(s) of the specified field by the amount provided.
|
static PatchOperation |
increment(String field,
Number amount)
Creates a new "increment" patch operation which will increment the
value(s) of the specified field by the amount provided.
|
boolean |
isAdd()
Returns
true if this is an "add" patch operation. |
boolean |
isCopy()
Returns
true if this is a "copy" patch operation. |
boolean |
isIncrement()
Returns
true if this is an "increment" patch operation. |
boolean |
isMove()
Returns
true if this is a "move" patch operation. |
boolean |
isRemove()
Returns
true if this is an "remove" patch operation. |
boolean |
isReplace()
Returns
true if this is an "replace" patch operation. |
boolean |
isTransform()
Returns
true if this is a "transform" patch operation. |
static PatchOperation |
move(JsonPointer from,
JsonPointer field)
Creates a new "move" patch operation which will move the value found at `from` to `path`.
|
static PatchOperation |
move(String from,
String field)
Creates a new "move" patch operation which will move the value found at `from` to `path`.
|
static PatchOperation |
operation(String operation,
JsonPointer field,
Object value)
Creates a new patch operation having the specified operation type, field,
and value(s).
|
static PatchOperation |
operation(String operation,
String field,
Object value)
Creates a new patch operation having the specified operation type, field,
and value(s).
|
static PatchOperation |
remove(JsonPointer field)
Creates a new "remove" patch operation which will remove the specified
field.
|
static PatchOperation |
remove(JsonPointer field,
Object value)
Creates a new "remove" patch operation which will remove the provided
value(s) from the specified field.
|
static PatchOperation |
remove(String field)
Creates a new "remove" patch operation which will remove the specified
field.
|
static PatchOperation |
remove(String field,
Object value)
Creates a new "remove" patch operation which will remove the provided
value(s) from the specified field.
|
static PatchOperation |
replace(JsonPointer field,
Object value)
Creates a new "replace" patch operation which will replace the value(s)
of the specified field with the provided value(s).
|
static PatchOperation |
replace(String field,
Object value)
Creates a new "replace" patch operation which will replace the value(s)
of the specified field with the provided value(s).
|
JsonValue |
toJsonValue()
Returns a JSON value representation of this patch operation.
|
String |
toString() |
static PatchOperation |
transform(JsonPointer field,
Object transform)
Creates a new "transform" patch operation which sets the value at field based on a
transformation.
|
static PatchOperation |
transform(String field,
Object transform)
Creates a new "transform" patch operation which sets the value at field based on a
transformation.
|
static PatchOperation |
valueOf(JsonValue json)
Parses the provided JSON content as a patch operation.
|
static List<PatchOperation> |
valueOfList(JsonValue json)
Parses the provided JSON content as a list of patch operations.
|
public static final String FIELD_FIELD
public static final String FIELD_FROM
public static final String FIELD_OPERATION
public static final String FIELD_VALUE
public static final String OPERATION_ADD
public static final String OPERATION_INCREMENT
public static final String OPERATION_REMOVE
public static final String OPERATION_REPLACE
public static final String OPERATION_MOVE
public static final String OPERATION_COPY
public static final String OPERATION_TRANSFORM
public static PatchOperation add(JsonPointer field, Object value)
field
- The field to be added.value
- The new value(s) to be added, which may be a JsonValue
or a JSON object, such as a String
, Map
, etc.NullPointerException
- If the value is null
.public static PatchOperation add(String field, Object value)
field
- The field to be added.value
- The new value(s) to be added, which may be a JsonValue
or a JSON object, such as a String
, Map
, etc.NullPointerException
- If the value is null
.public static PatchOperation increment(JsonPointer field, Number amount)
field
- The field to be incremented.amount
- The amount to be added or removed (if negative) from the
field's value(s).NullPointerException
- If the amount is null
.public static PatchOperation increment(String field, Number amount)
field
- The field to be incremented.amount
- The amount to be added or removed (if negative) from the
field's value(s).NullPointerException
- If the amount is null
.public static PatchOperation remove(JsonPointer field)
field
- The field to be removed.public static PatchOperation remove(JsonPointer field, Object value)
field
- The field to be removed.value
- The value(s) to be removed, which may be a JsonValue
or a JSON object, such as a String
, Map
, etc.public static PatchOperation remove(String field)
field
- The field to be removed.public static PatchOperation remove(String field, Object value)
field
- The field to be removed.value
- The value(s) to be removed, which may be a JsonValue
or a JSON object, such as a String
, Map
, etc.public static PatchOperation replace(JsonPointer field, Object value)
field
- The field to be replaced.value
- The new value(s) for the field, which may be a
JsonValue
or a JSON object, such as a String
,
Map
, etc.public static PatchOperation replace(String field, Object value)
field
- The field to be replaced.value
- The new value(s) for the field, which may be a
JsonValue
or a JSON object, such as a String
,
Map
, etc.public static PatchOperation move(JsonPointer from, JsonPointer field)
from
- The field to be moved.field
- The destination path for the moved valueNullPointerException
- If the from or path is null
.public static PatchOperation move(String from, String field)
from
- The field to be moved.field
- The destination path for the moved valueNullPointerException
- If the from or path is null
.public static PatchOperation copy(JsonPointer from, JsonPointer field)
from
- The field to be copied.field
- The destination path for the copied valueNullPointerException
- If the from or path is null
.public static PatchOperation copy(String from, String field)
from
- The field to be copied.field
- The destination path for the copied valueNullPointerException
- If the from or path is null
.public static PatchOperation transform(JsonPointer field, Object transform)
field
- The field to be set.transform
- The transform to be used to set the field value.NullPointerException
- If the transform is null
.public static PatchOperation transform(String field, Object transform)
field
- The field to be set.transform
- The transform to be used to set the field value.NullPointerException
- If the transform is null
.public static PatchOperation operation(String operation, JsonPointer field, Object value)
operation
- The type of patch operation to be performed.field
- The field targeted by the patch operation.value
- The possibly null
value for the patch operation, which
may be a JsonValue
or a JSON object, such as a
String
, Map
, etc.public static PatchOperation operation(String operation, String field, Object value)
operation
- The type of patch operation to be performed.field
- The field targeted by the patch operation.value
- The possibly null
value for the patch operation, which
may be a JsonValue
or a JSON object, such as a
String
, Map
, etc.public static PatchOperation copyOf(PatchOperation operation)
operation
- The patch operation to be defensively copied.public static PatchOperation valueOf(JsonValue json) throws BadRequestException
json
- The patch operation to be parsed.BadRequestException
- If the JSON value is not a JSON patch operation.public static List<PatchOperation> valueOfList(JsonValue json) throws BadRequestException
json
- The list of patch operations to be parsed.BadRequestException
- If the JSON value is not a list of JSON patch operations.public JsonPointer getField()
public JsonPointer getFrom()
public String getOperation()
public JsonValue getValue()
null
.public boolean isAdd()
true
if this is an "add" patch operation.true
if this is an "add" patch operation.public boolean isIncrement()
true
if this is an "increment" patch operation.true
if this is an "increment" patch operation.public boolean isRemove()
true
if this is an "remove" patch operation.true
if this is an "remove" patch operation.public boolean isReplace()
true
if this is an "replace" patch operation.true
if this is an "replace" patch operation.public boolean isMove()
true
if this is a "move" patch operation.true
if this is a "move" patch operation.public boolean isCopy()
true
if this is a "copy" patch operation.true
if this is a "copy" patch operation.public boolean isTransform()
true
if this is a "transform" patch operation.true
if this is a "transform" patch operation.public JsonValue toJsonValue()
Copyright © 2010-2018, ForgeRock All Rights Reserved.