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

Need to serialize a property that can come as a single object or an object array

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None

    Description

      Hi there.

      I faced and exception today and don't quite know how to work around it. Couldn't find anything similar online aswell.

      So, I consume a webservice, and it returns me an xml that I convert to a json and later on save it to a Mongo database. I'm saving it as BsonDocument, once I don't know every property on the json to map a working C# model (I can't ensure that the property will always be the same).
      Later on the code, I retrive that information to a previously maped model class and I add the "BsonIgnoreExtraElements" annotation to it. Inside that class, I've got a List<> property, but in my json the equivalent of that property, it's a single object, not an array.

      Is there anyway that I force that value to always be serialized as an array? Even if on the mongo database it was saved as a single.

      Thanks !

      Attachments

        Activity

          People

            wan.bachtiar@mongodb.com Wan Bachtiar
            rafaelgianine Rafael Gianine
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: