public interface JSONDelta
JSON
.
A JSONDelta describes the differences between two JSON values. Unlike a
binary delta
, a
structural delta can be queried to determine its effect. The
removed()
and inserted()
methods provide full details of
the differences between the two values.
An instance can be created from two JSON values using
JSON.diff(JSON)
.
JSONDeltas are useful for identifying small changes to complex JSON values.
Here's any example of how to use this class to filter interesting changes in
a ValueStream
.
public class ExampleStream implements ValueStream<JSON> { public void onValue(String topicPath, JSON oldValue, JSON newValue) { JSONDelta delta = newValue.diff(oldValue); if (!delta.removed().intersection("/address").isEmpty() || !delta.inserted().intersection("/address").isEmpty()) { // The "address" field has changed. processAddress(newValue); } } // ... }
Modifier and Type | Interface and Description |
---|---|
static interface |
JSONDelta.ChangeMap
An unmodifiable map describing the changes to a JSON value.
|
Modifier and Type | Method and Description |
---|---|
boolean |
hasChanges()
Returns whether the two JSON values used to create this instance are
different.
|
JSONDelta.ChangeMap |
inserted()
Returns the parts of the second JSON value not found in the first JSON
value.
|
JSONDelta.ChangeMap |
removed()
Returns the parts of the first JSON value not found in the second JSON
value.
|
JSONDelta.ChangeMap removed()
JSONDelta.ChangeMap inserted()
boolean hasChanges()
Copyright © 2022 Push Technology Ltd. All Rights Reserved.