Tarmil / FSharp.SystemTextJson

System.Text.Json extensions for F# types
MIT License
323 stars 44 forks source link

Custom serializer/`JsonConverter` for a record #185

Open rynoV opened 2 months ago

rynoV commented 2 months ago

Thanks for making this!

I didn't see this in the docs so I thought I'd mention it here: when registering a custom JsonConverter for a type in JsonFSharpTypes (e.g. records), it seems necessary to add it to the JsonSerializerOptions.Converters list before adding the json fsharp serializer options with AddToJsonSerializerOptions. Otherwise the fsharp record converter takes precedence.

Adding the JsonConverter directly to the record doesn't seem to take precedence. And it doesn't seem like using ToJsonSerializerOptions would work either.

nkosi23 commented 3 days ago

Thanks, this has been very helpful to me.