Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-909

New [BsonIgnoreIfNoElements] attribute

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 1.8.3
    • Component/s: Feature Request
    • Environment:
      any

      Hi,

      I have to serialize the following class with C# driver:

      class Sample
      {
          [BsonId]
          public object id {get;set;}
          public string name {get;set}
          public Sample2 sample2 {get;set;}
      }
      
      class Sample2
      {
          [BsonIgnoreIfNull]
          public DateTime? DealDate { get; set; }
      
          [BsonIgnoreIfNull]
          public DateTime? FinishDate { get; set; }
      }
      

      but I want to ignore sample2 field if this subdoc has no fields (if both dates are null).

      For now I can use ShouldSerializesample2, but i would like to implement that with some attribute like [BsonIgnoreIfNoElements]. If json has complex structure with nested nullable elements in subdocs it will be best solution.

      It's an open question how often this situation arises. Maybe this attribute deserves implementation. What's your opinion?

            Assignee:
            Unassigned Unassigned
            Reporter:
            stormbringer1984 ??????? ??????? ???????
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: