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

JsonJacksonApprovals should accept instance of ObjectMapper #478

Open
olsavmic opened this issue Mar 9, 2024 · 1 comment
Open

JsonJacksonApprovals should accept instance of ObjectMapper #478

olsavmic opened this issue Mar 9, 2024 · 1 comment

Comments

@olsavmic
Copy link

olsavmic commented Mar 9, 2024

The org.approvaltests.JsonJacksonApprovals class should accept ObjectMapper as an optional parameter, similarly to the org.approvaltests.JsonApprovals accepting a Function1<GsonBuilder, GsonBuilder> gsonBuilder.

The main motivation is to have consistent serialization with the rest of the application, allowing to perform pretty-printing without changing the semantics of the output (typically NULL values present vs missing).

I don't think there is any reason to modify the mapper during verification, therefore I find it safe to pass the actual instance instead of some ObjectMapper factory/builder.


Thank you for the tooling! I really appreciate such a zero-config snapshotting functionality :)

@olsavmic
Copy link
Author

olsavmic commented Mar 9, 2024

Since Jackson supports ordering of properties and map entries out of the box (ORDER_MAP_ENTRIES_BY_KEYS, SORT_PROPERTIES_ALPHABETICALLY options), allowing to pass an instance of ObjectMapper will make the JsonJacksonApprovals implementation on par with JsonApprovals in terms of features.

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

1 participant