Package dev.dokimos.core.evaluators
Class StructuralMatchEvaluator
java.lang.Object
dev.dokimos.core.BaseEvaluator
dev.dokimos.core.evaluators.StructuralMatchEvaluator
- All Implemented Interfaces:
Evaluator
Compares the actual output against the expected output as JSON structures rather than as opaque
strings.
Both operands are normalized to a Jackson JsonNode tree and compared with a hand-written
recursive comparator (Jackson's JsonNode.equals(Object) is deliberately not used —
it treats 5 and 5.0 as different and would corrupt eval results). The comparator:
- Compares numeric leaves by
BigDecimal.compareTo(BigDecimal)(scale-insensitive but otherwise exact, so1.0equals1.00and5equals5.0, while genuinely distinct values never collapse). Matches by value in both modes. - Honors
StructuralMatchMode:STRICTrequires the exact field set and exact array order;LENIENTallows extra actual fields (subset match) and ignores array order as a multiset. - Treats a
nullvalue and a missing field as equal in LENIENT and distinct in STRICT. - Fails loudly on duplicate object keys (via the strict-duplicate-detection comparison reader) and on non-finite numbers (NaN / Infinity).
- Parses a
Stringoperand as JSON before comparing, so CSV / JSON-string datasets compare object-against-object rather than against a quoted string.
Scoring. By default the score is the fraction of matching leaf paths in
[0.0, 1.0]. In STRICT the denominator is the union of the expected and actual leaf paths
(extra fields penalize); in LENIENT the denominator is the expected leaf paths only (extras are
ignored). Calling StructuralMatchEvaluator.Builder.binary() collapses the score to 1.0 (everything matches)
or 0.0 (anything differs) for exact-contract gates.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for constructing structural match evaluators. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Creates a new builder for constructing structural match evaluators.Methods inherited from class dev.dokimos.core.BaseEvaluator
evaluate, evaluateAsync, evaluateAsync, name, threshold
-
Method Details
-
builder
Creates a new builder for constructing structural match evaluators.- Returns:
- a new builder
-