<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:35:52 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-120] ToJson() serialization of Abstract classes</title>
                <link>https://jira.mongodb.org/browse/CSHARP-120</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>
&lt;p&gt;If I do this:&lt;br/&gt;
using System;&lt;/p&gt;

&lt;p&gt;using MongoDB.Bson;&lt;/p&gt;

&lt;p&gt;namespace BsonTest&lt;br/&gt;
{&lt;br/&gt;
    internal sealed class Program&lt;br/&gt;
    {&lt;br/&gt;
        private static void Main(string[] args)&lt;br/&gt;
        {&lt;br/&gt;
            Payload payload = new ChildOfPayLoad &lt;/p&gt;
{
                name=&quot;Justin&quot;,
                email=&quot;justin@domain.com&quot;
            }
&lt;p&gt;;&lt;/p&gt;

&lt;p&gt;            payload.ToJson();&lt;/p&gt;

&lt;p&gt;            Console.Write(&quot;Press any key to continue . . . &quot;);&lt;br/&gt;
            Console.ReadKey(true);&lt;br/&gt;
        }&lt;br/&gt;
    }&lt;/p&gt;

&lt;p&gt;        public abstract class Payload&lt;br/&gt;
    {&lt;br/&gt;
        private static readonly string _myId = &quot;something&quot;;&lt;br/&gt;
        public string myId&lt;br/&gt;
        {&lt;br/&gt;
            get &lt;/p&gt;
{ return _myId; }
&lt;p&gt;            set { }&lt;br/&gt;
        }&lt;br/&gt;
        public abstract string someType &lt;/p&gt;
{ get; set; }&lt;br/&gt;
    }&lt;br/&gt;
&lt;br/&gt;
    public class ChildOfPayLoad : Payload&lt;br/&gt;
    {&lt;br/&gt;
        &lt;br/&gt;
        public string name { get; set; }
&lt;p&gt;        public string email &lt;/p&gt;
{ get; set; }
&lt;p&gt;        public override string someType&lt;br/&gt;
        {&lt;br/&gt;
            get &lt;/p&gt;
{ return &quot;Something&quot;; }
&lt;p&gt;            set { }&lt;br/&gt;
        }&lt;br/&gt;
    }&lt;/p&gt;

&lt;p&gt;}&lt;br/&gt;
I get:&lt;/p&gt;

&lt;p&gt;System.ArgumentException: An item with the same key has already been added.&lt;br/&gt;
   at static void System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)&lt;br/&gt;
   at void System.Collections.Generic.Dictionary`2&lt;span class=&quot;error&quot;&gt;&amp;#91;System.String,MongoDB.Bson.DefaultSerializer.BsonMemberMap&amp;#93;&lt;/span&gt;.Insert(String key, BsonMemberMap value, Boolean add)&lt;br/&gt;
   at void System.Collections.Generic.Dictionary`2&lt;span class=&quot;error&quot;&gt;&amp;#91;System.__Canon,System.__Canon&amp;#93;&lt;/span&gt;.Add(__Canon key, __Canon value)&lt;br/&gt;
   at void MongoDB.Bson.DefaultSerializer.BsonClassMap.Freeze() in d:\justin&apos;s projects\mongo-csharp\Bson\DefaultSerializer\BsonClassMap.cs:line 303&lt;br/&gt;
   at static BsonClassMap MongoDB.Bson.DefaultSerializer.BsonClassMap.LookupClassMap(Type classType) in d:\justin&apos;s projects\mongo-csharp\Bson\DefaultSerializer\BsonClassMap.cs:line 186&lt;br/&gt;
   at void MongoDB.Bson.DefaultSerializer.BsonClassMapSerializer.Serialize(BsonWriter bsonWriter, Type nominalType, Object value, Boolean serializeIdFirst) in d:\justin&apos;s projects\mongo-csharp\Bson\DefaultSerializer\BsonClassMapSerializer.cs:line 160&lt;br/&gt;
   at static void MongoDB.Bson.Serialization.BsonSerializer.Serialize(BsonWriter bsonWriter, Type nominalType, Object value, Boolean serializeIdFirst) in d:\justin&apos;s projects\mongo-csharp\Bson\Serialization\BsonSerializer.cs:line 257&lt;br/&gt;
   at static void MongoDB.Bson.Serialization.BsonSerializer.Serialize(BsonWriter bsonWriter, Object value, Boolean serializeIdFirst) in d:\justin&apos;s projects\mongo-csharp\Bson\Serialization\BsonSerializer.cs:line 232&lt;br/&gt;
   at static String MongoDB.Bson.BsonExtensionMethods.ToJson(Object obj, Boolean serializeIdFirst, BsonJsonWriterSettings settings) in d:\justin&apos;s projects\mongo-csharp\Bson\BsonExtensionMethods.cs:line 110&lt;br/&gt;
   at static String MongoDB.Bson.BsonExtensionMethods.ToJson(Object obj, BsonJsonWriterSettings settings) in d:\justin&apos;s projects\mongo-csharp\Bson\BsonExtensionMethods.cs:line 120&lt;br/&gt;
   at static String MongoDB.Bson.BsonExtensionMethods.ToJson(Object obj) in d:\justin&apos;s projects\mongo-csharp\Bson\BsonExtensionMethods.cs:line 93&lt;br/&gt;
   at static void BsonTest.Program.Main(String[] args) in c:\Users\DearingJ\Documents\SharpDevelop Projects\BsonTest\BsonTest\Program.cs:line 16&lt;/p&gt;</description>
                <environment></environment>
        <key id="13852">CSHARP-120</key>
            <summary>ToJson() serialization of Abstract classes</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="zippy1981">Justin Dearing</reporter>
                        <labels>
                    </labels>
                <created>Thu, 2 Dec 2010 23:17:50 +0000</created>
                <updated>Thu, 2 Apr 2015 18:27:41 +0000</updated>
                            <resolved>Fri, 3 Dec 2010 15:21:06 +0000</resolved>
                                    <version>0.9</version>
                                    <fixVersion>0.9</fixVersion>
                                                        <votes>0</votes>
                                    <watches>0</watches>
                                                                                                                                                            <comments>
                            <comment id="21012" author="rstam" created="Fri, 3 Dec 2010 15:21:06 +0000"  >&lt;p&gt;For serialization purposes ignore any overridden properties because they will already be serialized by the base class.&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                            <subtask id="13856">CSHARP-122</subtask>
                    </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|hrh9kn:</customfieldvalue>

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