Skip to content

Conversation

@deblockt
Copy link
Owner

@deblockt deblockt commented Apr 21, 2024

Summary

This PR introduces a more flexible matcher architecture and adds the ability to treat null and empty arrays [] as equivalent.

Closes #17

Breaking Changes

CompositeJsonMatcher API

The constructor now accepts varargs instead of 3 fixed parameters:

// Before
new CompositeJsonMatcher(arrayMatcher, objectMatcher, primitiveMatcher)

// After
new CompositeJsonMatcher(matcher1, matcher2, matcher3, ...)

PartialJsonMatcher interface

New method manage(JsonNode expected, JsonNode received) required to determine if a matcher handles a comparison.

LenientNumberPrimitivePartialMatcher

No longer uses delegation pattern. Must be used alongside StrictPrimitivePartialMatcher:

// Before
new LenientNumberPrimitivePartialMatcher(new StrictPrimitivePartialMatcher())

// After
new LenientNumberPrimitivePartialMatcher(),
new StrictPrimitivePartialMatcher()

New Features

NullEqualsEmptyArrayMatcher

Treats null and [] as equivalent:

final var jsonMatcher = new CompositeJsonMatcher(
    new NullEqualsEmptyArrayMatcher(),     // Must be first
    new LenientJsonArrayPartialMatcher(),
    new LenientJsonObjectPartialMatcher(),
    new LenientNumberPrimitivePartialMatcher(),
    new StrictPrimitivePartialMatcher()
);

// These now match with 100% similarity:
// {"items": null}  vs  {"items": []}

Note: Missing properties do NOT match empty arrays (intentional design decision).

Changes

  • CompositeJsonMatcher: Refactored to use varargs and dynamic matcher selection via manage() method
  • PartialJsonMatcher: Added manage() method to interface
  • LenientNumberPrimitivePartialMatcher: Simplified to only handle numbers
  • NullEqualsEmptyArrayMatcher: New matcher for null/empty array equivalence
  • README: Complete rewrite with improved structure and documentation
  • Tests: Added unit tests and integration tests for all new functionality

Test Plan

  • All existing tests pass
  • Unit tests for NullEqualsEmptyArrayMatcher
  • Integration tests for nested structures
  • Tests for LenientNumberPrimitivePartialMatcher refactoring
  • Updated CompositeJsonMatcherTest for new API

🤖 Generated with Claude Code

@deblockt deblockt force-pushed the feat/allowNullEqualsEmpty branch from 12cd392 to 8a3dba8 Compare April 21, 2024 16:47
deblockt and others added 2 commits January 1, 2026 19:17
- Fix CompositeJsonMatcherTest to configure manage() method on mocks
- Add comprehensive tests for NullEqualsEmptyArrayMatcher

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@deblockt deblockt force-pushed the feat/allowNullEqualsEmpty branch from 8a3dba8 to cacc78d Compare January 1, 2026 18:19
deblockt and others added 2 commits January 1, 2026 19:26
- Create integration test package
- Move NullEqualsEmptyArrayMatcher integration tests to new class
- Add tests for nested structures (deeply nested, inside arrays, multiple fields)
- Keep only unit tests in NullEqualsEmptyArrayMatcherTest

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Document that missing property does NOT match empty array
(intentional design decision per PR description)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@deblockt deblockt marked this pull request as ready for review January 1, 2026 18:29
deblockt and others added 4 commits January 1, 2026 19:31
- Improve English and structure
- Update installation to version 2.0.0 with Java 21/Jackson 3.x note
- Add Quick Start section
- Document all available matchers in tables
- Add NullEqualsEmptyArrayMatcher section
- Add Creating Custom Matchers section
- Update examples for new CompositeJsonMatcher API

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Remove delegation pattern - matcher now only handles numbers.
Use alongside StrictPrimitivePartialMatcher for full primitive support.

Before:
  new LenientNumberPrimitivePartialMatcher(new StrictPrimitivePartialMatcher())

After:
  new LenientNumberPrimitivePartialMatcher(),
  new StrictPrimitivePartialMatcher()

- Remove delegated field and constructor parameter
- manage() now returns true only for numeric nodes
- Add Javadoc with usage example
- Update all tests and documentation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@deblockt deblockt merged commit 8864b74 into master Jan 1, 2026
1 check passed
@deblockt deblockt deleted the feat/allowNullEqualsEmpty branch January 1, 2026 18:49
@deblockt deblockt changed the title feat: allow to have equality between null and empty array feat: flexible matcher architecture and null/empty array equivalence Jan 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ignore difference between null or empty array

2 participants