Search code examples
c#.netasp.net-mvcjson.netjsonconvert

JsonConvert.PopulateObject not working with boolean value


The below code wont map false over a true property using JsonConvert.PopulateObject. The other properties work just fine. Am I doing something wrong?

JsonConvert.PopulateObject(json, request);

JSON

{ "EventId": 146282, "Name": "api division 9", "Order": 4, "Description": "test", "Active": false  }

Account.cs

[DataContract(Name = "Request", Namespace = "")]
    public class ApiCreateDivisionRequest : ApiAuthorizedRequest
    {
    [DataMember(IsRequired = false, EmitDefaultValue = false)]
    public bool Active { get; set; }

enter image description here

enter image description here


Solution

  • EmitDefaultValue needs to be true