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

Serialize/Deserialize for readonly properties

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Done
    • Icon: Minor - P4 Minor - P4
    • 1.4.1
    • 1.4
    • Feature Request
    • All
    • Fully Compatible

    Description

      Sometimes we have some readonly properties, but they should be persisted to db, mainly for index and search purpose.

      These properties's values are generated from other properties, but is criticaly useful when perform a search in db, so they should be readonly and should be serialized to BSON.

      My suggest is that the C# driver by default serialize all read/write properties (same as current), but give a configure possibility to serialize readonly properties, such as:

      map.MapProperty(c => c.ReadOnlyProperty);

      Then once a value is deserialized from BSON, and corresonding property doesn't have a set accessor, C# driver does not throw an exception, this causes a modification to /Bson/Serialization/BsonMemberMap.cs (line 560 as in master on github).

      Attachments

        Activity

          People

            craig.wilson@mongodb.com Craig Wilson
            otakustay Gray Zhang
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: