I use the newtonsoft library to deserialize a slightly complex object and fall into a trap where the identifiers inside the MetaData object are not populated and all other values look normal. All basic objects are derived from a class model that has basic properties such as Id. Does anyone have any suggestions as to what is going on here?
This is the JSON that I use for testing, the top level object is the page:
{ "CreatedOn": "2012-07-30T13:42:45+01:00", "CreatedBy": "33576D49-B799-4326-812C-D6A3C47B7035", "Name": "Icecream", "Metadata": [ { "CreatedOn": "2012-07-30T14:06:31+01:00", "ModifiedOn": "2012-07-30T14:06:31+01:00", "ModifiedBy": "53D947AC-0D7B-42C4-929E-DAFC25932784", "Name": "Colour", "Value": "Blue", "NodeReference": "834a2734-e807-4eb7-a242-c26d785681f3", "Scope": "Draft", "Id": "032488bd-158c-4064-93ec-44bd11c4e642", "CreatedBy": "53D947AC-0D7B-42C4-929E-DAFC25932784" }, { "CreatedOn": "2012-07-30T13:48:49+01:00", "ModifiedOn": "2012-07-30T14:23:20+01:00", "ModifiedBy": "10E0821E-1982-4C24-B9E1-35FAF9A547BB", "Name": "Topping", "Value": "Chocolate sprinkles", "NodeReference": "834a2734-e807-4eb7-a242-c26d785681f3", "Scope": "Live", "Id": "241afb40-0d83-4599-a05e-aec1a6cdef41", "CreatedBy": "CE1F79DE-9ECF-456F-8C17-D9B7E4B6FCA7" } ], "WikiResources": [ ], "FileResources": [ ], "Links": [ ], "Id": "834a2734-e807-4eb7-a242-c26d785681f3" }
Here is the (simplified) version of my code:
public abstract class Model { protected Guid? _id; public Guid? Id { get { return _id;} set { _id = value; IsDirty = true; } } private string _name; //eg page Heading public string Name { get { return _name; } set { _name = value; IsDirty = true; } } private DateTime _createdOn; public DateTime CreatedOn { get { return _createdOn; } set { _createdOn = value; IsDirty = true; } } private string _createdBy; public string CreatedBy { get { return _createdBy; } set { _createdBy = value; IsDirty = true; } } [JsonIgnore] public bool IsDirty { get; set; } [JsonIgnore] public bool IsNew { get; set; } private List<MetaDatum> _metadata; public List<MetaDatum> MetaData { get { return _metadata; } set { _metadata = value; } } } public class MetaDatum : Model, IModel { //other properties and methods omitted
Rusty source share