Skip to content

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

2 participants