C
C#2y ago
Brent

❔ C# Dictionary Json Serialization problems

Hey everyone! I'm trying to Serialize a Dictionary with a class 'Manager' as Key, and an Enum 'Privilege' as Value. I know I could just use a normal list and put Privilege in the Manager class, but I have to use a Dictionary for a school project. Im getting this error: System.NotSupportedException: 'The type 'Globals.Manager' is not a supported dictionary key using converter of type 'System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1[Globals.Manager]'. The unsupported member type is located on type 'Globals.Privilege'. Path: $.' I already added the IEquatable<T> interface to the manager class, but still getting the same error. Could anyone help me please? Thanks in advance!
2 Replies
Angius
Angius2y ago
JSON doesn't support complex keys Keys in JSON are strings, plain as that
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server