Created
August 13, 2021 16:20
-
-
Save JonCanning/c8de46db00b031195c58447ffd10a62c to your computer and use it in GitHub Desktop.
Sensible json defaults
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Json | |
open Microsoft.FSharpLu.Json | |
open Newtonsoft.Json | |
open Newtonsoft.Json.Serialization | |
open Newtonsoft.Json.Converters | |
let private compactJsonSerializerSettings = | |
let settings = Compact.TupleAsArraySettings.settings | |
StringEnumConverter(CamelCaseText = true) | |
|> settings.Converters.Add | |
settings.ContractResolver <- CamelCasePropertyNamesContractResolver() | |
settings.NullValueHandling <- NullValueHandling.Ignore | |
settings.MissingMemberHandling <- MissingMemberHandling.Ignore | |
JsonConvert.DefaultSettings <- fun () -> settings | |
settings | |
let serialize o = | |
JsonConvert.SerializeObject(o, compactJsonSerializerSettings) | |
let deserialize<'T> json = | |
JsonConvert.DeserializeObject<'T>(json, compactJsonSerializerSettings) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment