8000 feat(NewtonsoftJson): backport Serdes ctor auto* options from STJ side of the house · Issue #98 · jet/FsCodec · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
feat(NewtonsoftJson): backport Serdes ctor auto* options from STJ side of the house #98
Open
@bartelink

Description

@bartelink

Backport the autoTypeSafeEnumToJsonString and autoUnionToJsonObject options to avoid the nasty surprised the default impl causes when (not if!) people fall into the default rendering trap for things lke:

a) TypeSafeEnums e.g. type ProductId = ProductA | ProductB (where you just want "ProductA", as the TypeSafeEnumconverter would do if applied explicitly)
b) Unions that should render as a JSON object (record)

 type UnionThatShouldBeAnObject =
     | SimpleProduct of master: ProductId
     | PairedProduct of {| primary: ProductId; backup: ProductId |}

will render as { "Case": "PairedProduct", "primary": "ProductA", "backup": "ProductA"} or { "Case": "PairedProduct", "master": "ProductA"}, as it would if you applied the UnionConverter explicitly

#96 is a very important related safety feature too

i.e.prevent:

"items": [
        {
          "serviceId": "5c8795be52e34e82883d61babed19513",
          "serviceKind": {
            "Case": "ProductA"
          }
        },
        {
          "serviceId": "8a55ebbf0d404485b50da95bdb53f7b3",
          "serviceKind": {
            "Case": "ProductB"
          }
        }
      ]
    },

and default to

"items": [
                            {
                                "serviceId": "5c8795be52e34e82883d61babed19513",
                                "serviceKind": "ProductB"
                            },
                            {
                                "serviceId": "8a55ebbf0d404485b50da95bdb53f7b3",
                                "serviceKind": "ProductA"
                            }
                        ]

related: JamesNK/Newtonsoft.Json#1662 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0