Class StructuralMatchEvaluator

java.lang.Object
dev.dokimos.core.BaseEvaluator
dev.dokimos.core.evaluators.StructuralMatchEvaluator
All Implemented Interfaces:
Evaluator

public class StructuralMatchEvaluator extends BaseEvaluator
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, so 1.0 equals 1.00 and 5 equals 5.0, while genuinely distinct values never collapse). Matches by value in both modes.
  • Honors StructuralMatchMode: STRICT requires the exact field set and exact array order; LENIENT allows extra actual fields (subset match) and ignores array order as a multiset.
  • Treats a null value 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 String operand 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.

  • Method Details