aboutsummaryrefslogtreecommitdiff
path: root/jsonmatch/interface.go
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2026-04-01 15:46:23 +0200
committerStefan Majewsky <majewsky@gmx.net>2026-04-01 15:47:01 +0200
commitcfc6d2d5b9ed9656165670e6ec262841aade3660 (patch)
treebc495fc17377af70ae2b981d7fd93babad85559a /jsonmatch/interface.go
parentca7ccbadbc19c2cb28f1b7edfcc845b9d7888adc (diff)
downloadgo-gg-1.6.0.tar.gz
jsonmatch: add Irrelevantv1.6.0
Diffstat (limited to 'jsonmatch/interface.go')
-rw-r--r--jsonmatch/interface.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/jsonmatch/interface.go b/jsonmatch/interface.go
index de6ef81..047a4b7 100644
--- a/jsonmatch/interface.go
+++ b/jsonmatch/interface.go
@@ -283,3 +283,22 @@ func (f capturedField) MarshalJSON() ([]byte, error) {
func (f capturedField) UnmarshalJSON(buf []byte) error {
return errors.New("cannot unmarshal into jsonmatch.CaptureField()")
}
+
+type irrelevant struct{}
+
+// Irrelevant returns a slot that can be placed in a jsonmatch.Object or jsonmatch.Array instance
+// to ignore the contents of certain fields or array elements during an assertion.
+//
+// Irrelevant() slots only work inside data structures that DiffAgainst() knows how to recurse into.
+// Please refer to the documentation on type Diffable for details.
+func Irrelevant() any {
+ return irrelevant{}
+}
+
+// MarshalJSON implements the json.Marshaler interface.
+//
+// This implementation ensures that `irrelevant` renders in a readable way
+// when a larger value containing it is serialized for a "type mismatch" or "value mismatch" error message.
+func (irrelevant) MarshalJSON() ([]byte, error) {
+ return []byte(`"<irrelevant>"`), nil
+}