Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider JsonComparator implementation for Spring Framework 6.2.0 #767

Closed
commonquail opened this issue May 26, 2024 · 5 comments
Closed

Comments

@commonquail
Copy link

commonquail commented May 26, 2024

This is to let JsonUnit know that Spring Framework 6.2.0 is expected to include an o.s.t.w.s.r.ContentResultMatchers::json overload that takes an o.s.t.j.JsonComparator, a BiFunction<@Nullable String, @Nullable String, JsonComparison>, that evaluates a comparison of actual and expected JSON values. JsonUnit may wish to consider this extension mechanism as a complement to its existing Spring Framework integrations.

It looks to me like no official public API of JsonUnit facilitates an ergonomic implementation of JsonComparator but that perhaps the internal Diff would be the implementation to base an extension on. For now, the following is the plainest implementation I can come up with:

        MockMvcResultMatchers.content().json(read("/foo.json"), (expectedJson, actualJson) -> {
            JsonAssertions.assertThatJson(actualJson).when(Option.IGNORING_EXTRA_FIELDS).isEqualTo(expectedJson);
            return JsonComparison.match();
        });

See also

@commonquail commonquail changed the title Consider JsonComparator implementation for Spring Framework 6.2.0 Consider JsonComparator implementation for Spring Framework 6.3.0 May 26, 2024
@commonquail commonquail changed the title Consider JsonComparator implementation for Spring Framework 6.3.0 Consider JsonComparator implementation for Spring Framework 6.2.0 May 26, 2024
@lukas-krecan
Copy link
Owner

Hi, thanks. I will look into that.

@lukas-krecan
Copy link
Owner

Basic support is here https://github.com/lukas-krecan/JsonUnit/pull/772/files

@commonquail
Copy link
Author

That's quite elegant

@lukas-krecan
Copy link
Owner

It will be part of 4.x release once Spring 6.2 is out

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

No branches or pull requests

2 participants