Skip to content
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

feat(NewtonsoftJson): backport Serdes ctor auto* options from STJ side of the house #98

Open
bartelink opened this issue Jul 23, 2023 · 0 comments

Comments

@bartelink
Copy link
Collaborator

bartelink commented Jul 23, 2023

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)

@bartelink bartelink changed the title Feature: NewtonsoftJson backport auto* from STJ side of the house feat(NewtonsoftJson): backport Serdes ctor auto* options from STJ side of the house Aug 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant