Snapper icon indicating copy to clipboard operation
Snapper copied to clipboard

Plain text serialization

Open artempyanykh opened this issue 3 years ago • 2 comments

Is your feature request related to a problem? Please describe. Currently snapper uses Json serialization. This is not well suited for my domain as my objects are F# types and their Json representation is extremely verbose compared to the default auto-generated ToString representation. This makes inspecting snapshots hard.

Describe the solution you'd like I'd like to use plain text serialization for for my snapshots.

Describe alternatives you've considered N/A

Additional context N/A

artempyanykh avatar Feb 13 '22 20:02 artempyanykh

Hey @artempyanykh,

Thanks for your request. I haven't personally used F# much but your request does look quite similar to some of the other request regarding customising how Snapper serialises the snapshots. I'll have a think about how best to allow for this customisation.

Do you happen to have an example of what a snapshot looks like currently when this is used in F#?

theramis avatar Feb 23 '22 08:02 theramis

@theramis sure, Here's the string repr:

Bind (false, "x2", Lit (Int 42), Var "x2")

And here's the JSON one:

{
    "Case": "Bind",
    "Fields": [
      false,
      "x2",
      {
        "Case": "Lit",
        "Fields": [
          {
            "Case": "Int",
            "Fields": [
              42
            ]
          }
        ]
      },
      {
        "Case": "Var",
        "Fields": [
          "x2"
        ]
      }
  ]
}

The original type definition can be found here: https://github.com/artempyanykh/Fang/blob/main/Core/Lang.fs Usage of sharpshooter is here: https://github.com/artempyanykh/Fang/blob/main/Tests/ParserTests.fs

artempyanykh avatar Feb 26 '22 12:02 artempyanykh

Hey @artempyanykh,

do you think you could solve you issue by using this? https://theramis.github.io/Snapper/#/pages/snapper/custom_snapshot_settings

You could implement a custom converter to convert objects like these to a nicer json format?

theramis avatar Dec 14 '22 23:12 theramis

Oh, missed the notification! Thanks for the update @theramis! Yeah, I solved my problems with serialization.

artempyanykh avatar Feb 12 '23 18:02 artempyanykh