Could be one of those days where I can't see what is infront of me but when I try to use the jsonserializer Populate function to map to an object - it fails to do so, and I'm not sure why. the object returned just has the default values for everything. Condensed code:
string json = @"
{
""Notification"": {
""Id"": 4,
""CreatedById"": 1,
""CreatedBy"": null,
""CreatedDateTime"": ""2023-05-31T21:44:44.9659592+01:00"",
""PushMessage"": ""Notify me now"",
""ScheduledDateTime"": ""2023-05-31T22:46:00+01:00"",
""Reach"": 1,
""OrganizationId"": 1,
""Organization"": {
""Id"": 1,
""Name"": ""orgname""
},
""UserNotifications"": [],
""Value"": 1,
""DisplayName"": ""OrgNotification""
}
}";
JObject jo = JObject.Parse(json);
var target = new Notification();
serializer.Populate(jo.CreateReader(), target);
public class Notification{
private string displayname;
private int _value;
public int Id { get; set; }
public int CreatedById { get; set; }
public User CreatedBy { get; set; }
public DateTimeOffset CreatedDateTime { get; set; }
public string PushMessage { get; set; }
public DateTimeOffset? ScheduledDateTime { get; set; }
public int Reach { get; set; }
public int OrganizationId { get; set; }
public Organization Organization { get; set; }
public string DisplayName { get{
displayname = "OrgNotification";
return displayname;} }
public int Value { get{
_value = 1;
return _value;} }
}
public class Organization{
public int Id { get; set; }
public string Name { get; set; }
}