You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
Hi @rynoV I am using custom JsonConverter attributes on some of my record and union types but serializer won't use them if I include JsonFSharpOptions in my JsonSerializerOptions.
I can't register all custom converters here in JsonSerializerOptions as I can't reference them and I don't like idea of adding them all in one place even if I could.
Any suggestion what to try? Thanks.
My options:
letoptions= JsonSerializerOptions ()
options.PropertyNamingPolicy <- JsonNamingPolicy.CamelCase
options.WriteIndented <-true
options.IndentSize <-4
options.DefaultIgnoreCondition <- JsonIgnoreCondition.WhenWritingNull
options.NumberHandling <- JsonNumberHandling.AllowReadingFromString
options.Encoder <- JavaScriptEncoder.Default
options.Converters.Add (DateTimeConverterJsonConverter ())
options.Converters.Add (DateTimeOffsetConverterJsonConverter ())
options.Converters.Add (GuidJsonConverter ())// with this part, my custom converter don't work, without it all goodletfsharpOptions=
JsonFSharpOptions
.Default()
.WithIncludeRecordProperties()
.WithUnionNamedFields()
.WithSkippableOptionFields()
fsharpOptions.AddToJsonSerializerOptions (options)
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 inJsonFSharpTypes
(e.g. records), it seems necessary to add it to theJsonSerializerOptions.Converters
list before adding the json fsharp serializer options withAddToJsonSerializerOptions
. 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 usingToJsonSerializerOptions
would work either.The text was updated successfully, but these errors were encountered: