I am using Json.Net to serialize and deserialize an object.
I am experiencing an issue where the deserialized object recordPosted has zero as its Id.
Whereas the Serialized record will contain an Id of 180
JsonSerializerSettings jsSettings = new JsonSerializerSettings();
jsSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
var recordAsJson = JsonConvert.SerializeObject(recordToUpdate,
Formatting.None, jsSettings);
//recordAsJson = {"Id":180,....
var recordPosted = JsonConvert.DeserializeObject<record>(recordAsJson);
//recordPosted = Id : 0
How would I resolve this?
Edit
public virtual int Id { get; private set; }
Json.NET doesn’t set private property setters by default. Either make the setter public or place a [JsonProperty] attribute on the property.