Hello. When I try to serialize Dictionary with integer key, it throw System.NotSupportedException.
I think it makes sense to support Json serialization which Dictionary has ToString-able key. for example, when we run ToString for int or boolean, it return "123" or "true". I think that key is ToString-able key.
Verison
System.Text.Json Nuget Version : 4.6.0-preview8.19405.3
Code
var dictionary = new Dictionary<int, string>
{
[5] = "five"
};
JsonSerializer.Serialize(dictionary);
Expected
But what happen
Error System.NotSupportedException Thrown
Actually, there is compatibility problem when I change Newtonsoft.Json to System.Text.Json. They return string as I expected. I think System.Text.Json don't have to be compatible but... you know.
Hello. When I try to serialize Dictionary with integer key, it throw System.NotSupportedException.
I think it makes sense to support Json serialization which Dictionary has
ToString-able key. for example, when we run ToString for int or boolean, it return "123" or "true". I think that key isToString-able key.Verison
System.Text.Json Nuget Version : 4.6.0-preview8.19405.3
Code
Expected
But what happen
Error
System.NotSupportedExceptionThrownActually, there is compatibility problem when I change Newtonsoft.Json to System.Text.Json. They return string as I expected. I think System.Text.Json don't have to be compatible but... you know.