Jericho / CakeMail.RestClient

.NET wrapper for the CakeMail API
MIT License
9 stars 3 forks source link

Bug with MemberStatus set to "active_bounced" in a Cakemail List. #26

Closed sarrazinc closed 8 years ago

sarrazinc commented 8 years ago

Hi,

I'm having a crash on the Cakemail API deserialization in the method "GetListMembers". A member has been set to the "active_bounced" state, which doesn't exists in the ListMemberStatus Enumeration (there is a state "inactive_bounced" however).

To fix this issue locally, I downloaded the source code from your repository and added the "active_bounced" value into the ListMemberStatus Enumeration. Here's the resulting class that fixed the issue (notice the new ActiveBounced value, set to the corresponding value). Do you think you could update your Enumeration with this one so I could use your nuget package again, instead of the version I compiled locally?


namespace CakeMail.RestClient.Models
{
    [JsonConverter(typeof(StringEnumConverter))]
    public enum ListMemberStatus
    {
        [EnumMember(Value = "active")]
        Active,
        [EnumMember(Value = "unsubscribed")]
        Unsubscribed,
        [EnumMember(Value = "deleted")]
        Deleted,
        [EnumMember(Value = "inactive_bounced")]
        InactiveBounced,
        [EnumMember(Value = "active_bounced")]
        ActiveBounced,
        [EnumMember(Value = "spam")]
        Spam
    }
}

To help you understand the issue, here's the full Stack Trace that I was receiving:



Exception: Newtonsoft.Json.JsonSerializationException
Message: Error converting value "active_bounced" to type 'CakeMail.RestClient.Models.ListMemberStatus'. Path '[1299].status', line 1, position 513484.
Source: Newtonsoft.Json
   at Newtonsoft.Json.Converters.StringEnumConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.Linq.JToken.ToObject(Type objectType, JsonSerializer jsonSerializer)
   at Newtonsoft.Json.Linq.JToken.ToObject(Type objectType)
   at Newtonsoft.Json.Linq.JToken.ToObject[T]()
   at CakeMail.RestClient.CakeMailRestClient.ExecuteRequest[T](String urlPath, IEnumerable`1 parameters, String propertyName)
   at CakeMail.RestClient.CakeMailRestClient.GetListMembers(String userKey, Int64 listId, Nullable`1 status, String query, Nullable`1 sortBy, Nullable`1 sortDirection, Nullable`1 limit, Nullable`1 offset, Nullable`1 clientId)

Nested Exception

Exception: System.ArgumentException
Message: Requested value 'active_bounced' was not found.
Source: mscorlib
   at System.Enum.EnumResult.SetFailure(ParseFailureKind failure, String failureMessageID, Object failureMessageFormatArgument)
   at System.Enum.TryParseEnum(Type enumType, String value, Boolean ignoreCase, EnumResult& parseResult)
   at System.Enum.Parse(Type enumType, String value, Boolean ignoreCase)
   at Newtonsoft.Json.Converters.StringEnumConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)

Thanks for your Cakemail wrapper, we're loving it!

Cedric

Jericho commented 8 years ago

Thanks for reporting this issue and more importantly thanks for doing the research to resolve it. I will add the enum value and publish updated package.

Jericho commented 8 years ago

Updated nuget package has been published but nuget.org hasn't indexed it yet. As soon as nuget.org indexes it, you'll be able to update your reference.

Thanks again for reporting the issue.

sarrazinc commented 8 years ago

Wow, that was fast. Thanks for fixing it so quickly!