add method
Returns a copy of document
with the newValue
added at the referenced location.
The semantics of this method is the same as the "add" operation described in RFC 6902 (JSON Patch).
- If the target location specifies an array index, the value is inserted at the specified index shifting existing values.
- If the target location is an key in an object, it will be added or replaced
by the
newValue
If any of the intermediate keys and indexes is missing, a BadRoute exception will be thrown.
Implementation
@override
Object? add(Object? document, Object? newValue) {
final node = parent.read(document);
try {
return parent.write(document, _reference.add(node, newValue));
} on ReferenceFailure {
throw BadRoute(this, document);
}
}