origin-energy / java-snapshot-testing

Facebook style snapshot testing for JAVA Tests
MIT License
109 stars 15 forks source link

Empty Snapshot when implementing own Serializer #165

Closed jackmatt2 closed 6 months ago

jackmatt2 commented 6 months ago

Discussed in https://github.com/origin-energy/java-snapshot-testing/discussions/164

Originally posted by **ClaudioZesiger** April 10, 2024 Hello, I implemented my own Serializer with Jsonb. The snapshot is written well into the snap-file. But when comparing the snapshot to another snapshot, the body of the existing snapshot from the file is always an empty string. This is my apply method ` @Override public Snapshot apply(Object o, SnapshotSerializerContext context) { String json = this.jsonb.toJson(o); return context.toSnapshot(json); } ` The jsonb object is initialized. I saw that the regex in the implementation does not support line breaks. File Snapshot.java. ` String regex = "^(?.*?)(\\[(?.*)\\])?=(?
\\{.*\\})?(?(.*)$)"; ` But normally any JSON should be formatted for readability. Any ideas about this? Regards C
jackmatt2 commented 6 months ago

There indeed appears to be an issue with headers + JSON body when parsed using the REGEX. Should be fixed in the upcoming 4.0.8 release

The Maven release is being flakey today so I will try it again tomorrow.