How to deserialize object derived from Exception class using Json.net?

前端 未结 3 1800
时光取名叫无心
时光取名叫无心 2020-12-03 21:10

I\'m trying to deserialize object derived from Exception class:

[Serializable]
public class Error : Exception, ISerializable
{
    public string ErrorMessage         


        
3条回答
  •  时光说笑
    2020-12-03 21:48

    Alternatively, you can choose the OptIn strategy and define the properties that should be processed. In case of your example:

    [JsonObject(MemberSerialization.OptIn)]
    public class Error : Exception, ISerializable
    {
        [JsonProperty(PropertyName = "error")]
        public string ErrorMessage { get; set; }
    
        [JsonConstructor]
        public Error() { }
    }
    

    (Credits go to this library)

提交回复
热议问题