approvals / ApprovalTests.Java

ApprovalTest verification library for Java
Apache License 2.0
329 stars 73 forks source link

JsonJacksonApprovals should accept instance of ObjectMapper #478

Open olsavmic opened 3 months ago

olsavmic commented 3 months ago

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 commented 3 months ago

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.