Hello I want to deserialize a class and in this class is a enum value:
[JsonConverter(typeof(StringEnumConverter))]
public enum MessageType {
Verify,
Disconnect,
}
[Serializable]
public class SocketMessage {
public Dictionary<String, String> Header { get; private set; }
public MessageType MessageType { get; private set; }
public SocketMessage(MessageType type) {
Header = new Dictionary<String, String>();
MessageType = type;
}
public void AddHeaderData(String key, String data) {
Header.Add(key, data);
}
public byte[] ToJSONBytes() {
String json = JsonConvert.SerializeObject(this);
return Encoding.UTF8.GetBytes(json);
}
public static SocketMessage FromJSONBytes(byte[] json) {
String s = Encoding.UTF8.GetString(json);
return JsonConvert.DeserializeObject<SocketMessage>(s);
}
}
The dictionary will be correctly deserialized but the enum always get his default value >verify< the json looks like this: {"Header":{"Test":"Test"},"MessageType":"Disconnect"}
I really don't understand why it happens
I appreciate any help!