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
Allow specifying which attributes should apply to a given property or union case in the options. This is useful to override the format of a type that is not under the developer's control, or simply to keep DTOs lean.
Example:
typeMyRecord={ x:int }letoptions=
JsonFSharpOptions()
.WithOverrides(fun o -> dict [
typeof<MyRecord>, o.WithOverrideProperty("x",[JsonNameAttribute "y"])])
.ToJsonSerializerOptions()
JsonSerializer.Serialize({ x =1}, o)// --> {"y":1}
Example combined with #180 to fully control the format of the standard library's Result<'ok, 'error>:
letoptions=
JsonFSharpOptions()
.WithOverrides(fun o -> dict [
typedefof<Result<_,_>>, o
.WithUnionInternalTag()
.WithUnionNamedFields()
.WithUnionTagName("isSuccess")
.WithOverrideCase("Ok",[
JsonNameAttribute true
JsonNameAttribute("value", Field ="ResultValue")])
.WithOverrideCase("Error",[
JsonNameAttribute false
JsonNameAttribute("error", Field ="ErrorValue")])])
JsonSerializer.Serialize(Ok 42, options)// --> {"isSuccess":true,"value":42}
JsonSerializer.Serialize(Error "Internal error", options)// --> {"isSuccess":false,"error":"Internal error"}
The text was updated successfully, but these errors were encountered:
Allow specifying which attributes should apply to a given property or union case in the options. This is useful to override the format of a type that is not under the developer's control, or simply to keep DTOs lean.
Example:
Example combined with #180 to fully control the format of the standard library's
Result<'ok, 'error>
:The text was updated successfully, but these errors were encountered: