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
Since .NET 6, the handling of dictionary keys can be customized using JsonConverter.Write/ReadAsPropertyName. Our Map converter should try use these methods in the same way, and only fall back to array-of-pairs in JSON if it can't.
The text was updated successfully, but these errors were encountered:
It's actually not really possible to choose the format based on whether the key type's converter supports {Read|Write}AsPropertyName. There isn't a flag that tells whether they're supported; just these two methods, that will either succeed or fail when called.
So a better option would be to follow what @cmeeren suggests in #152 and allow choosing the format in JsonFSharpOptions.
A version, corresponding to the current default, where Maps whose keys are string and single-case-union-of-string are serialized as objects, and other keys are serialized as array-of-pairs.
A new version where all keys are handled with {Read|Write}AsPropertyName. This will therefore always use JSON objects, but only support key types that support {Read|Write}AsPropertyName. This includes types such as int, Guid, DateTime, etc. With Allow using single-case unions as dictionary keys #161 implemented, this also includes single-case-union-of-string. In other words, the set of key types supported by this format is a superset of the key types that are serialized as JSON objects in the current version.
Maybe even a version using array-of-pairs regardless of the key type, because it's easy to do and may be appealing to some users for both supporting all key types and being consistent across key types.
Since .NET 6, the handling of dictionary keys can be customized using
JsonConverter.Write/ReadAsPropertyName
. Our Map converter should try use these methods in the same way, and only fall back to array-of-pairs in JSON if it can't.The text was updated successfully, but these errors were encountered: