Skip to content

How to ignore fields like dates and IDs? #88

Answered by jackmatt2
alvinwo asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, you can use regular Jackson configuration to ignore dates etc.

You will need to create a serializer similar to this Hibernate one.
https://github.com/origin-energy/java-snapshot-testing#example-hibernateserializer

Then customise as needed

objectMapper.addMixIn(DateTime.class, IgnoreTypeMixin.class);
objectMapper.addMixIn(Instant.class, IgnoreTypeMixin.class);
objectMapper.addMixIn(Date.class, IgnoreTypeMixin.class);

Update your snapshot.properties to include the new serializer (alternatively replace the default one)

serializer.custom=com.example.MyCustomSerializer
expect.serializer('custom').toMatchSnapshot(foo)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@alvinwo
Comment options

Answer selected by jackmatt2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants