-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathStrictJsonObjectPartialMatcher.java
More file actions
40 lines (32 loc) · 1.61 KB
/
StrictJsonObjectPartialMatcher.java
File metadata and controls
40 lines (32 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.deblock.jsondiff.matcher;
import com.deblock.jsondiff.diff.JsonDiff;
import com.deblock.jsondiff.diff.JsonObjectDiff;
import tools.jackson.databind.node.ObjectNode;
public class StrictJsonObjectPartialMatcher implements PartialJsonMatcher<ObjectNode> {
@Override
public JsonDiff jsonDiff(Path path, ObjectNode expectedJson, ObjectNode receivedJson, JsonMatcher jsonMatcher) {
final var jsonDiff = new JsonObjectDiff(path);
expectedJson.properties()
.forEach(entry -> {
final var expectedPropertyName = entry.getKey();
final var expectedValue = entry.getValue();
final var receivedValue = receivedJson.get(expectedPropertyName);
if (receivedValue == null) {
jsonDiff.addNotFoundProperty(expectedPropertyName, expectedValue);
} else {
final var diff = jsonMatcher.diff(path.add(Path.PathItem.of(expectedPropertyName)), expectedValue, receivedValue);
jsonDiff.addPropertyDiff(expectedPropertyName, diff);
}
});
receivedJson.properties()
.forEach(entry -> {
final var receivedPropertyName = entry.getKey();
final var receivedPropertyValue = entry.getValue();
final var expectedValue = expectedJson.get(receivedPropertyName);
if (expectedValue == null) {
jsonDiff.addExtraProperty(receivedPropertyName, receivedPropertyValue);
}
});
return jsonDiff;
}
}