Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Equinox.Codec out to FsCodec #156

Merged
merged 13 commits into from
Aug 30, 2019
Prev Previous commit
Next Next commit
Use Gardelloyd.NewtonsoftJson; lean on OptionConverter by default
  • Loading branch information
bartelink committed Aug 29, 2019
commit c6575c0347062de42886b6e0f6c9cc4397b1aa62
2 changes: 1 addition & 1 deletion DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ The fact that we have a `Cleared` Event stems from the fact that the spec define

The `Compacted` event is used to represent Rolling Snapshots (stored in-stream) and/or Unfolds (stored in Tip document-Item); For a real Todo list, using this facility may well make sense - the State can fit in a reasonable space, and the likely number of Events may reach an interesting enough count to justify applying such a feature
i) it should also be noted that Caching may be a better answer - note `Compacted` is also an `isOrigin` event - there's no need to go back any further if you meet one.
ii) we use an Array in preference to a [F#] `list`; while there are `ListConverter`s out there (notably not in [`Jet.JsonNet.Converters`](https://github.com/jet/Jet.JsonNet.Converters)), in this case an Array is better from a GC and memory-efficiency stance, and does not need any special consideration when using `Newtonsoft.Json` to serialize.
ii) we use an Array in preference to a [F#] `list`; while there are `ListConverter`s out there (notably not in [`FsCodec`](https://github.com/jet/FsCodec)), in this case an Array is better from a GC and memory-efficiency stance, and does not need any special consideration when using `Newtonsoft.Json` to serialize.

#### `State` + `initial`+`fold`

Expand Down
3 changes: 0 additions & 3 deletions samples/Store/Domain/Domain.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
<PackageReference Include="FSharp.Core" Version="4.3.4" Condition=" '$(TargetFramework)' == 'netstandard2.0' " />

<PackageReference Include="FSharp.UMX" Version="1.0.0" />
<PackageReference Include="Jet.JsonNet.Converters" Version="0.2.2" />
<PackageReference Include="Jet.JsonNet.Converters" Version="0.2.2" />
<PackageReference Include="TypeShape" Version="7.0.0" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion samples/Store/Domain/Infrastructure.fs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[<AutoOpen>]
module Domain.Infrastructure

open Gardelloyd.NewtonsoftJson
open FSharp.UMX
open Newtonsoft.Json
open Newtonsoft.Json.Converters.FSharp
open System

#if NET461
Expand Down
11 changes: 4 additions & 7 deletions samples/Store/Integration/CodecIntegration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type EventWithOption = { age : int option }

type EventWithUnion = { value : Union }
// Using converter to collapse the `fields` of the union into the top level, alongside the `case`
and [<Newtonsoft.Json.JsonConverter(typeof<Newtonsoft.Json.Converters.FSharp.UnionConverter>)>] Union =
and [<Newtonsoft.Json.JsonConverter(typeof<Gardelloyd.NewtonsoftJson.UnionConverter>)>] Union =
| I of Int
| S of MaybeInt
and Int = { i : int }
Expand All @@ -29,19 +29,16 @@ type SimpleDu =

let render = function
| EventA { id = id } -> sprintf """{"id":"%O"}""" id
| EventB { age = None } -> sprintf "{}"
| EventB { age = None } -> sprintf "{\"age\":null}"
| EventB { age = Some age } -> sprintf """{"age":%d}""" age
| EventC { value = I { i = i } } -> sprintf """{"value":{"case":"I","i":%d}}""" i
| EventC { value = S { maybeI = None } } -> sprintf """{"value":{"case":"S"}}"""
| EventC { value = S { maybeI = None } } -> sprintf """{"value":{"case":"S","maybeI":null}}"""
| EventC { value = S { maybeI = Some i } } -> sprintf """{"value":{"case":"S","maybeI":%d}}""" i
| EventD -> null
//| EventE i -> string i
//| EventF s -> Newtonsoft.Json.JsonConvert.SerializeObject s

let codec =
// Don't let json.net treat 't option as the DU it is internally
let settingsWithOptionSupport = Gardelloyd.NewtonsoftJson.Settings.Create(Newtonsoft.Json.Converters.FSharp.OptionConverter())
Gardelloyd.NewtonsoftJson.Codec.Create(settingsWithOptionSupport)
let codec = Gardelloyd.NewtonsoftJson.Codec.Create()

[<AutoData(MaxTest=100)>]
let ``Can roundtrip, rendering correctly`` (x: SimpleDu) =
Expand Down