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

[#162] Allow choosing the map format as object or array-of-pairs #169

Merged
merged 3 commits into from
Aug 13, 2023

Conversation

Tarmil
Copy link
Owner

@Tarmil Tarmil commented Aug 5, 2023

This fixes #162 by introducing the following format option:

type MapFormat =
    /// Always serialize Maps as JSON objects.
    /// Only supports the same key types as the built-in serializer for Dictionary.
    /// Requires System.Text.Json 8.0 or newer.
    | Object = 0
    /// Always serialize Maps as JSON arrays whose items are [key, value] JSON arrays.
    /// Supports all key types.
    | ArrayOfPairs = 1
    /// Serialize Maps as JSON objects if the key type is string or a single-case union wrapping string;
    /// otherwise, serialize Maps as JSON arrays whose items are [key, value] JSON arrays.
    /// Supports all key types.
    /// This is the default format.
    | ObjectOrArrayOfPairs = 2

Note: Object requires System.Text.Json 8.0 due to dotnet/runtime#77326.

@Tarmil Tarmil merged commit 119dab5 into master Aug 13, 2023
@Tarmil Tarmil deleted the map-format branch August 13, 2023 07:45
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

Successfully merging this pull request may close these issues.

Allow handling arbitrary Map keys as JSON object properties
1 participant