Open SpencerWaz opened 5 years ago
Considering it more, your converters are used to serialize to/from your API response.
To solve my issue I just inherited from your models and hid the base members
public class IntercomUser : User
{
new public List<IntercomSocialProfile> social_profiles { get; set; }
new public List<IntercomCompany> companies { get; set; }
new public List<IntercomSegment> segments { get; set; }
new public List<IntercomTag> tags { get; set; }
}
public class IntercomCompany : Company
{
new public List<IntercomTag> tags { get; set; }
}
public class IntercomSocialProfile : SocialProfile { }
public class IntercomSegment : Segment { }
public class IntercomTag : Tag { }
Then using automapper to map between
Mapper.Initialize(config =>
{
config.CreateMap<User, IntercomUser>();
config.CreateMap<Company, IntercomCompany>();
config.CreateMap<Tag, IntercomTag>();
config.CreateMap<SocialProfile, IntercomSocialProfile>();
config.CreateMap<Segment, IntercomSegment>();
});
var users = new List<User>();
# get users
var mapped = Mapper.Map<List<IntercomUser>>(users);
var converted = JsonConvert.SerializeObject(mapped);
var deserialized = JsonConvert.DeserializeObject<List<IntercomUser>>(converted);
Kindof a workaround.. but it works well imho. This allowed me to re serialize / deserialize the models.
You should consider removing the JsonConverter attributes and just use them during the serialization operation instead. I'll see if I can make some time and add a PR.
Thanks!
@SpencerWaz I'm running into the same issue that serialisation is generating an issue. Do you perhaps have an PR available?
@MennoKlup Sorry for the delayed response.. this isn't my main account. I just moved on after using the workaround mentioned earlier.. but I suppose I can look into adding a PR later tonight when I'm off the clock.
I'm getting an exception thrown when serializing and then de serializing Users.
Intercom: Error while serializing AppCount endpoint json result. Newtonsoft.Json: Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '[0].social_profiles', line 1, position 1297
Repo:
The stack trace shows the exception being thrown from: Intercom.Converters.AttributeConverters.ListJsonConverter.ReadJson