|
7 | 7 |
|
8 | 8 | import java.util.Optional;
|
9 | 9 |
|
| 10 | +/** |
| 11 | + * Base class for JSON pattern nodes. |
| 12 | + */ |
10 | 13 | public abstract class JsonPatternNode {
|
| 14 | + /** |
| 15 | + * The string representation of the expected JSON pattern. |
| 16 | + */ |
11 | 17 | private final String expected;
|
12 | 18 |
|
13 |
| - public JsonPatternNode(@NotNull String expected) { |
| 19 | + /** |
| 20 | + * Constructor of the JSON pattern node. |
| 21 | + * @param expected The string representation of the expected JSON pattern. |
| 22 | + */ |
| 23 | + protected JsonPatternNode(@NotNull String expected) { |
14 | 24 | this.expected = expected;
|
15 | 25 | }
|
16 | 26 |
|
| 27 | + /** |
| 28 | + * Matches the JSON pattern node against the actual JSON node. |
| 29 | + * @param path The JSON path to the actual JSON node. |
| 30 | + * @param actualNode The actual JSON node. |
| 31 | + * @return An empty optional if the actual JSON node matches the pattern node, or an error detail if it does not match. |
| 32 | + */ |
17 | 33 | @NotNull
|
18 | 34 | public abstract Optional<JsonMatchErrorDetail> matches(@NotNull JsonPath path, @NotNull JsonNode actualNode);
|
19 | 35 |
|
| 36 | + /** |
| 37 | + * Creates an error detail. |
| 38 | + * @param path The JSON path to the actual JSON node. |
| 39 | + * @param actualNode The actual JSON node. |
| 40 | + * @param reason The reason why the actual JSON node does not match the pattern node. |
| 41 | + * @return An error detail. |
| 42 | + */ |
20 | 43 | @NotNull
|
21 | 44 | protected JsonMatchErrorDetail error(@NotNull JsonPath path, @NotNull JsonNode actualNode, @NotNull String reason) {
|
22 | 45 | return new JsonMatchErrorDetail(path, actualNode.toString(), expected, reason);
|
23 | 46 | }
|
24 | 47 |
|
| 48 | + /** |
| 49 | + * Returns if the pattern node can be missing. |
| 50 | + * @return True if the pattern node can be missing, false otherwise. |
| 51 | + */ |
25 | 52 | protected boolean canBeMissing() {
|
26 | 53 | return false;
|
27 | 54 | }
|
|
0 commit comments