-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom serializer/JsonConverter
for a record
#185
Comments
Thanks, this has been very helpful to me. |
Hi @rynoV I am using custom I can't register all custom converters here in Any suggestion what to try? Thanks. My options: let options = 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 good
let fsharpOptions =
JsonFSharpOptions
.Default()
.WithIncludeRecordProperties()
.WithUnionNamedFields()
.WithSkippableOptionFields()
fsharpOptions.AddToJsonSerializerOptions (options) |
@draganjovanovic1 If you use |
@Tarmil I tried adding |
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: