-
-
Save AlexZeitler/0699ce404f16e6cf87e268e5496f41ac 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 Infrastructure | |
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