Allow customising the serializer settings for Snapshots
Is your feature request related to a problem? Please describe.
Allow adjustment of the JsonSerializerSettings in JObjectHelper that is used by JsonSnapshotStore, so that snapshots can be made more readable e.g. when using custom JsonConverters they are taken into account.
e.g. an example of the current behaviour
"myList": [
{
"Name": "My SmartEnum",
"Value": "My Value that should be used instead"
}
],
after allowing to add converters for instance
"myList": [
"My Value that should be used instead"
],
Describe the solution you'd like
Not yet full thought through, but maybe
- Allow defining a convention based class e.g.
**CustomSnapshotSerialzation**that could expose either the completeJsonSerializerSettingsorhooksto be called by the default implementation when adding converters.
What would be great is to at least be able to add the following
serializerSettings.Converters.Add(new SmartEnumValueConverter<MySmartEnum, string>());
Describe alternatives you've considered
Additional context
Hey @SbiCA,
Thanks for making the issue. I've definitely thought about doing this in the past so that users could use their own serialiser settings.
I've shied away from it in the past as I didn't want to expose the internal working of Snapper. Specifically the usage of Newtonsoft.Json. I will most likely be switching to System.Text.Json in the future once it is more feature rich and ideally the change should not be noticeable by consumers.
As an alternative have you thought about converting your object into a jobject using your own serialiser before calling Snapper? e.g. something like this. You could abstract out the conversion into a method if needed.
JObject.FromObject(obj, JsonSerializer.Create(JsonSettings)).ShouldMatchSnapshot();