-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathOnlyErrorDiffViewer.java
More file actions
61 lines (50 loc) · 1.71 KB
/
OnlyErrorDiffViewer.java
File metadata and controls
61 lines (50 loc) · 1.71 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package com.deblock.jsondiff.viewer;
import com.deblock.jsondiff.diff.JsonDiff;
import com.deblock.jsondiff.matcher.Path;
import tools.jackson.databind.JsonNode;
/**
* List all error on a string
* call .toString to get the error string
*/
public class OnlyErrorDiffViewer implements JsonDiffViewer {
private final StringBuilder stringBuilder = new StringBuilder();
@Override
public void matchingProperty(Path path, JsonDiff value) { }
@Override
public void primaryMatching(Path path, JsonNode value) {
}
@Override
public void nonMatchingProperty(Path path, JsonDiff diff) {
diff.display(this);
}
@Override
public void missingProperty(Path path, JsonNode value) {
stringBuilder
.append("The property \"")
.append(path)
.append("\" in the expected json is not found\n");
}
@Override
public void extraProperty(Path path, JsonNode extraReceivedValue) {
stringBuilder
.append("The property \"")
.append(path)
.append("\" in the received json is not expected\n");
}
@Override
public void primaryNonMatching(Path path, JsonNode expected, JsonNode value) {
stringBuilder
.append("The property \"").append(path)
.append("\" didn't match. Expected ").append(expected)
.append(", Received: ").append(value)
.append("\n");
}
public String toString() {
return stringBuilder.toString();
}
public static JsonDiffViewer from(JsonDiff jsonDiff) {
final var result = new OnlyErrorDiffViewer();
jsonDiff.display(result);
return result;
}
}