<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:43:00 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[CSHARP-2599] Need to serialize a property that can come as a single object or an object array</title>
                <link>https://jira.mongodb.org/browse/CSHARP-2599</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;Hi there.&lt;/p&gt;

&lt;p&gt;I faced and exception today and don&apos;t quite know how to work around it. Couldn&apos;t find anything similar online aswell.&lt;/p&gt;

&lt;p&gt;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&apos;m saving it as BsonDocument, once I don&apos;t know every property on the json to map a working C# model (I can&apos;t ensure that the property will always be the same).&lt;br/&gt;
Later on the code, I retrive that information to a previously maped model class and I add the &quot;BsonIgnoreExtraElements&quot; annotation to it. Inside that class, I&apos;ve got a List&amp;lt;&amp;gt; property, but in my json the equivalent of that property, it&apos;s a single object, not an array.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;Thanks !&lt;/p&gt;</description>
                <environment></environment>
        <key id="745268">CSHARP-2599</key>
            <summary>Need to serialize a property that can come as a single object or an object array</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="9">Done</resolution>
                                        <assignee username="wan.bachtiar@mongodb.com">Wan Bachtiar</assignee>
                                    <reporter username="rafaelgianine">Rafael Gianine</reporter>
                        <labels>
                    </labels>
                <created>Thu, 25 Apr 2019 19:37:20 +0000</created>
                <updated>Thu, 25 Jun 2020 02:21:38 +0000</updated>
                            <resolved>Thu, 25 Jun 2020 02:21:38 +0000</resolved>
                                                                                        <votes>0</votes>
                                    <watches>3</watches>
                                                                                                                <comments>
                            <comment id="2271866" author="wan.bachtiar" created="Wed, 5 Jun 2019 06:42:00 +0000"  >&lt;blockquote&gt;&lt;p&gt;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.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Hi Rafael,&lt;/p&gt;

&lt;p&gt;You can register a custom serializer for a particular model to be treated with a special case. See also &lt;a href=&quot;http://mongodb.github.io/mongo-csharp-driver/2.8/reference/bson/serialization/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;mongo-csharp-driver: Serialization&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Also I&apos;d recommend to enforce the value consistency when, not after, writing to MongoDB.&lt;/p&gt;

&lt;p&gt;Please note that the CSHARP project is for reporting bugs or feature suggestions for the MongoDB .NET/C# driver. If you have any follow-up questions on the use of the C# driver, please post a question on &lt;a href=&quot;https://groups.google.com/forum/#!forum/mongodb-user&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;mongodb-user&lt;/a&gt; group with the relevant information. i.e. MongoDB .NET/C# driver version, example documents, example models, etc.&#160;&lt;/p&gt;

&lt;p&gt;Regards, &lt;br/&gt;
 Wan.&lt;/p&gt;</comment>
                            <comment id="2225266" author="jmikola@gmail.com" created="Thu, 25 Apr 2019 20:32:08 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=rafaelgianine&quot; class=&quot;user-hover&quot; rel=&quot;rafaelgianine&quot;&gt;rafaelgianine&lt;/a&gt;: You originally opened this issue in the CDRIVER project, which tracks the C driver. I&apos;ve moved this issue of to the CSHARP project, where it will hopefully get the attention of the C# driver developers.&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hul21j:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9223372036854775807</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>