CAMEL-22865: Add JSON comparison with unordered elements to MockValueBuilder#20961
CAMEL-22865: Add JSON comparison with unordered elements to MockValueBuilder#20961gnodet merged 1 commit intoapache:mainfrom
Conversation
…Builder This commit implements a new feature for the camel-mock component that allows JSON comparison while ignoring element order in arrays and objects. This is particularly useful when testing Camel routes with JSON payloads where the order of elements can vary. Key changes: - Added jsonEquals(Object expected) method to MockValueBuilder that defaults to ignoring array element order - Added jsonEquals(Object expected, boolean ignoreOrder) method for more control over comparison behavior - Implemented deep JSON comparison using camel-util-json library - Supports various input types: String, byte[], InputStream, JsonObject, JsonArray - Handles nested JSON structures (objects and arrays) - Provides semantic comparison that ignores key order in objects - Can optionally enforce strict array element order when needed Implementation details: - Uses Jsoner.deserialize() from camel-util-json for JSON parsing - Implements recursive comparison algorithm for nested structures - For unordered array comparison, uses a matching algorithm that finds corresponding elements - Handles primitives, nulls, booleans, numbers, and strings correctly Testing: - Added comprehensive test suite with 20 test cases covering: * JSON objects with different key orders * JSON arrays with different element orders (both strict and lenient) * Nested JSON structures * Mixed type arrays * Edge cases (empty objects/arrays, nulls, whitespace) * Error cases (mismatches, different structures) * Different input types (String, byte[]) All tests pass successfully.
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🤖 CI automation will test this PR automatically. 🐫 Apache Camel Committers, please review the following items:
|
|
That is a great idea to use camel-tooling-json and the JSooner parser we have so this is included out of the box in camel-mock |
Fixes CAMEL-22865
This commit implements a new feature for the camel-mock component that allows JSON comparison while ignoring element order in arrays and objects. This is particularly useful when testing Camel routes with JSON payloads where the order of elements can vary.
Key changes:
Implementation details: