2

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

Mike Flynn
  • 22,342
  • 54
  • 182
  • 341
  • You need to put the `[DataContract(Name = "Request", Namespace = "")]` on it, replicates the bug. Looks like `EmitDefaultValue` needs to be true. If you mark that as the answer Ill give it to you. – Mike Flynn Mar 11 '20 at 01:06
  • OK, once I added DataContract, [I was able to reproduce it](https://dotnetfiddle.net/1bZ9UX). – ProgrammingLlama Mar 11 '20 at 01:10
  • There seems to be an [issue](https://github.com/JamesNK/Newtonsoft.Json/issues/2294) for it. – ProgrammingLlama Mar 11 '20 at 01:11

1 Answers1

1

EmitDefaultValue needs to be true

Mike Flynn
  • 22,342
  • 54
  • 182
  • 341