<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:35:45 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-83] Generic lists, enumerables, etc... are not persisted as bson arrays</title>
                <link>https://jira.mongodb.org/browse/CSHARP-83</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;Given a class like this:&lt;/p&gt;

&lt;p&gt;public class Student&lt;br/&gt;
{&lt;br/&gt;
  public ObjectId Id &lt;/p&gt;
{ get; set; }&lt;br/&gt;
&lt;br/&gt;
  public List&amp;lt;int&amp;gt; Scores { get; set; }
&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;Scores is not persisted as a bson array, but rather as a document.&lt;/p&gt;

&lt;p&gt;I would assume this pertains to any property that is not defined as an array.&lt;/p&gt;

&lt;p&gt;IEnumerable&amp;lt;T&amp;gt;&lt;br/&gt;
ICollection&amp;lt;T&amp;gt;&lt;br/&gt;
IList&amp;lt;T&amp;gt;&lt;br/&gt;
HashSet&amp;lt;T&amp;gt;&lt;br/&gt;
List&amp;lt;T&amp;gt;&lt;br/&gt;
etc...&lt;/p&gt;</description>
                <environment></environment>
        <key id="13474">CSHARP-83</key>
            <summary>Generic lists, enumerables, etc... are not persisted as bson arrays</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="robert@mongodb.com">Robert Stam</assignee>
                                    <reporter username="craig.wilson@mongodb.com">Craig Wilson</reporter>
                        <labels>
                    </labels>
                <created>Fri, 22 Oct 2010 22:47:14 +0000</created>
                <updated>Thu, 2 Apr 2015 18:27:38 +0000</updated>
                            <resolved>Mon, 1 Nov 2010 05:39:33 +0000</resolved>
                                    <version>0.5</version>
                                    <fixVersion>0.7</fixVersion>
                                                        <votes>0</votes>
                                    <watches>0</watches>
                                                                                                                <comments>
                            <comment id="19897" author="rstam" created="Mon, 1 Nov 2010 05:39:33 +0000"  >&lt;p&gt;IEnumerable  and IEnumerable&amp;lt;T&amp;gt; values are now serialized as BsonArrays. Added a general mechanism to register generic serializer definitions (see EnumerableSerializer&amp;lt;T&amp;gt; and Lookup- and RegisterGenericSerializerDefinition).&lt;/p&gt;</comment>
                            <comment id="19888" author="craiggwilson" created="Sun, 31 Oct 2010 19:51:47 +0000"  >&lt;p&gt;1) Sounds good for not using ArrayList or other.&lt;/p&gt;

&lt;p&gt;2) I Like the non-string key versions to be persisted as an array of key value pairs.  That makes a lot of sense.&lt;/p&gt;

&lt;p&gt;All I really need out of this is transparent persistence of collections without requiring types to be placed into the database.&lt;/p&gt;</comment>
                            <comment id="19882" author="rstam" created="Sun, 31 Oct 2010 15:55:11 +0000"  >&lt;p&gt;Just wondering: why use ArrayList and HashTable at all? Would the following work just as well&lt;/p&gt;

&lt;p&gt;For IEnumerable use List&amp;lt;object&amp;gt;&lt;br/&gt;
For ICollection use List&amp;lt;object&amp;gt;&lt;br/&gt;
For IList use List&amp;lt;object&amp;gt;&lt;br/&gt;
For IDictionary use Dictionary&amp;lt;object, object&amp;gt;&lt;/p&gt;

&lt;p&gt;Also, do we have to restrict T in Dictionary&amp;lt;T,V&amp;gt; to be convertible to and from string? What we could do is:&lt;/p&gt;

&lt;p&gt;1. If T is string, serialize dictionary to a BsonDocument&lt;br/&gt;
2. If T is not string, serialize dictionary to an array of &lt;span class=&quot;error&quot;&gt;&amp;#91;key, value&amp;#93;&lt;/span&gt; pairs&lt;/p&gt;

&lt;p&gt;So for example, a property P of type Dictionary&amp;lt;K, V&amp;gt; would be serialized as:&lt;/p&gt;

{ ..., P : [[k1, v1], [k2, v2], ...], ... }</comment>
                            <comment id="19571" author="craiggwilson" created="Sun, 24 Oct 2010 23:50:12 +0000"  >&lt;p&gt;While that certainly is an option, I can&apos;t think of any benefit for it off the top of my head.  If you are using an interface, it means you rely on the interface and it&apos;s underlying implementation to provide the functionality necessary.  If you need specific functionality delivered only by a specific concrete class, then just declare the property as a concrete class.&lt;/p&gt;

&lt;p&gt;I personally try and stay away from any form of attributes.  It pollutes the class and takes it from being POCO (or POJO for you java folks) and makes it some sort of hybrid.&lt;/p&gt;

&lt;p&gt;So, as far as mapping goes:&lt;/p&gt;

&lt;p&gt;property type             implementation&lt;br/&gt;
IEnumerable            ArrayList&lt;br/&gt;
ICollection                ArrayList&lt;br/&gt;
IList                            ArrayList&lt;br/&gt;
IDictionary                 HashTable&lt;/p&gt;

&lt;p&gt;IEnumerable&amp;lt;T&amp;gt;      List&amp;lt;T&amp;gt;&lt;br/&gt;
ICollection&amp;lt;T&amp;gt;           List&amp;lt;T&amp;gt;&lt;br/&gt;
IList&amp;lt;T&amp;gt;                       List&amp;lt;T&amp;gt;&lt;br/&gt;
IDictionary&amp;lt;T,V&amp;gt;        Dictionary&amp;lt;T,V&amp;gt; //note, T must be convertible to and from a string&lt;/p&gt;

&lt;p&gt;HashSet&amp;lt;T&amp;gt;               HashSet&amp;lt;T&amp;gt;&lt;br/&gt;
List&amp;lt;T&amp;gt;                         List&amp;lt;T&amp;gt;&lt;br/&gt;
Dictionary&amp;lt;T,V&amp;gt;          Dictionary&amp;lt;T,V&amp;gt; //note, T must be convertible to and from a string&lt;/p&gt;


</comment>
                            <comment id="19569" author="scotthernandez" created="Sun, 24 Oct 2010 22:57:40 +0000"  >&lt;p&gt;The way we do this with in morphia (java mapper) is to specify the concrete class via an annotation (or a custom converter):&lt;/p&gt;

&lt;p&gt;public class Student { &lt;br/&gt;
    public ObjectId Id; &lt;br/&gt;
    @Property(concreteClass = ArrayList.class)&lt;br/&gt;
    public List&amp;lt;int&amp;gt; Scores; &lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;In the c# it would probably be something like this with an attribute.&lt;/p&gt;</comment>
                            <comment id="19539" author="rstam" created="Fri, 22 Oct 2010 23:24:05 +0000"  >&lt;p&gt;I like the way you think. I was hung up on trying to guarantee that the rehydrated object was identical to the original one. But I agree that that&apos;s not nearly as important as keeping the data platform neutral.&lt;/p&gt;</comment>
                            <comment id="19537" author="craiggwilson" created="Fri, 22 Oct 2010 23:05:58 +0000"  >&lt;p&gt;Before you take that stance, if I have declared a property as IList&amp;lt;int&amp;gt;, the it should imply that I simply don&apos;t care about the actual implementation of IList&amp;lt;int&amp;gt; is, just that is supports that interface.  In other words, don&apos;t serialize the type.  When you see an IList&amp;lt;T&amp;gt;, just bring it back in as List&amp;lt;int&amp;gt;.  When you see IEnumerable&amp;lt;T&amp;gt; or ICollection&amp;lt;T&amp;gt;, do the same thing.  There is no need to persist the type because we only care that whatever is rehydrated supports the interface.&lt;/p&gt;

&lt;p&gt;Also, placing .NET specific types into the document truly kills cross platform integration.  I have some apps that have a backend using mongodb-csharp and a front end using ruby.  If I had to instruct my ruby front end that IList[&lt;span class=&quot;error&quot;&gt;&amp;#91;something&amp;#93;&lt;/span&gt;] means whatever, it would be horrible.  It&apos;s just an array to mongodb.&lt;/p&gt;</comment>
                            <comment id="19536" author="rstam" created="Fri, 22 Oct 2010 22:52:43 +0000"  >&lt;p&gt;Good point. I think it&apos;s a side effect of being able to handle:&lt;/p&gt;

&lt;p&gt;public class Student {&lt;br/&gt;
    public ObjectId Id &lt;/p&gt;
{ get; set; }&lt;br/&gt;
    public IList&amp;lt;int&amp;gt; Scores { get; set; }
&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;where the Scores property is declared using an interface type. In this case the document has a discriminator (&quot;_t&quot;) to record what concrete class to instantiate when deserializing.&lt;/p&gt;

&lt;p&gt;I will look into serializing straight into an array when a discriminator is not required.&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|hrh9sf:</customfieldvalue>

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