Created
April 7, 2021 21:35
-
-
Save aspnetde/0b2c7a15d438c7237ad28fde339d30b9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
namespace Foo | |
open System.Text.Encodings.Web | |
open System.Text.Json | |
open System.Text.Json.Serialization | |
[<RequireQualifiedAccess>] | |
module JsonSerializer = | |
let private setupOptions (options: JsonSerializerOptions) = | |
options.PropertyNamingPolicy <- JsonNamingPolicy.CamelCase | |
options.MaxDepth <- 0 | |
options.Encoder <- JavaScriptEncoder.UnsafeRelaxedJsonEscaping | |
options.Converters.Add( | |
JsonFSharpConverter( | |
JsonUnionEncoding.UnwrapSingleCaseUnions | |
||| JsonUnionEncoding.FSharpLuLike, | |
unionTagNamingPolicy = JsonNamingPolicy.CamelCase | |
) | |
) | |
options.IgnoreNullValues <- true | |
options | |
let private options = JsonSerializerOptions() |> setupOptions | |
let serialize value = | |
JsonSerializer.Serialize(value, options) | |
let deserialize<'T> (json: string) = | |
JsonSerializer.Deserialize<'T>(json, options) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment