Skip to content

Instantly share code, notes, and snippets.

@johnazariah
Created May 20, 2014 05:27
Show Gist options
  • Save johnazariah/21ce1cea7464d0831826 to your computer and use it in GitHub Desktop.
Save johnazariah/21ce1cea7464d0831826 to your computer and use it in GitHub Desktop.
Serialization with FsPickler
type AccountIdentifier =
| AccountIdentifier of System.Guid
type Account = {
Identifier : AccountIdentifier
Name : string
}
open Nessos.FsPickler // https://www.nuget.org/packages/FsPickler/
[<EntryPoint>]
let main argv =
let id = System.Guid.NewGuid() |> AccountIdentifier
let account = {Identifier = id; Name = "Accounts Receiveable"}
let d = [ id, account ] |> Map.ofList
let fsp = new FsPickler()
let stream = new System.IO.MemoryStream()
fsp.Serialize<Map<AccountIdentifier, Account>>(stream, d)
stream.Seek(0L, System.IO.SeekOrigin.Begin) |> ignore
let roundTripResult = fsp.Deserialize<Map<AccountIdentifier, Account>>(stream)
printfn "%s" roundTripResult.[id].Name
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment