<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:38:11 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-918] There is no easy way to set a default serialization option for a type (even if it is in an array, dictionary, or derived class)</title>
                <link>https://jira.mongodb.org/browse/CSHARP-918</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;If you want (for example) to serialize all decimals as doubles (yes, I know about the loss of precision), there is no easy way to do so.&lt;/p&gt;

&lt;p&gt;    var conventions = new ConventionPack();&lt;br/&gt;
    conventions.Add(new MemberSerializationOptionsConvention(typeof(decimal), new RepresentationSerializationOptions(BsonType.Double)));&lt;br/&gt;
    ConventionRegistry.Register(&quot;Serialize decimal as double&quot;, conventions, t =&amp;gt; true);&lt;/p&gt;

&lt;p&gt;works for plain decimals in a class, but does not apply itself to arrays of decimals, or decimals in a dictionary, or arrays of decimals in a dictionary.&lt;/p&gt;

&lt;p&gt;It would be simpler to understand if all the Serializers had a static property for the default serialization method, so you could just do&lt;/p&gt;

&lt;p&gt;    DecimalSerializer.DefaultSerializationOptions = BsonType.Double;&lt;/p&gt;

&lt;p&gt;If that is considered too hacky, the alternative would be to make the array, dictionary, etc. deserializers honour registered conventions for their elements, instead of always using the hard coded default.&lt;/p&gt;
</description>
                <environment>Windows 8.1</environment>
        <key id="114799">CSHARP-918</key>
            <summary>There is no easy way to set a default serialization option for a type (even if it is in an array, dictionary, or derived class)</summary>
                <type id="2" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14711&amp;avatarType=issuetype">New Feature</type>
                                            <priority id="4" iconUrl="https://jira.mongodb.org/images/icons/priorities/minor.svg">Minor - P4</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="-1">Unassigned</assignee>
                                    <reporter username="nikkilocke">Nikki Locke</reporter>
                        <labels>
                            <label>deserialization</label>
                    </labels>
                <created>Wed, 26 Feb 2014 12:47:51 +0000</created>
                <updated>Thu, 22 May 2014 20:49:33 +0000</updated>
                            <resolved>Wed, 21 May 2014 19:32:50 +0000</resolved>
                                    <version>1.8.3</version>
                                    <fixVersion>2.0</fixVersion>
                                    <component>Serialization</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="593493" author="craiggwilson" created="Thu, 22 May 2014 20:49:33 +0000"  >&lt;p&gt;It will be in the next major release of the driver. FixVersion is labelled as 3.0. This will be a backwards breaking release in some regards, although we are trying to keep it relegated to configuration or low level ideas. &lt;/p&gt;

&lt;p&gt;You can pull successful nightly builds from our &lt;a href=&quot;https://www.myget.org/gallery/mongocsharpdriverbuild&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;build feed&lt;/a&gt;. You can also register the serializer globally using:&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;BsonSerializer.RegisterSerializer&amp;lt;decimal&amp;gt;(new DecimalSerializer().WithRepresentation(BsonType.Double));&lt;/tt&gt;&lt;/p&gt;

&lt;p&gt;Note that you could always do the above in relation to registering a serializer, but now you are able to set a representation directly onto the serializer.&lt;/p&gt;
</comment>
                            <comment id="593483" author="nikkilocke" created="Thu, 22 May 2014 20:41:58 +0000"  >&lt;p&gt;All decimals already are stored as strings by default (or have you changed that?). &lt;br/&gt;
You still haven&apos;t explained how to &quot;register a DecimalSerializer globally&quot;, or which version I need to download to enable the functionality. &lt;br/&gt;
Thanks, &lt;br/&gt;
Nikki&lt;/p&gt;


&lt;p&gt;&amp;#8211; &lt;br/&gt;
Sent from my Android device with K-9 Mail. Please excuse my brevity.&lt;/p&gt;</comment>
                            <comment id="592854" author="craiggwilson" created="Thu, 22 May 2014 12:09:32 +0000"  >&lt;p&gt;Sorry, I realize that was pretty cryptic. I think Robert said it best in the comment above mine.&lt;/p&gt;

&lt;p&gt;We used to store the representation separately from the serializer itself. In addition, it was changeable at runtime preventing someone from saying &quot;All Decimals should be stored as a string&quot;.  Since these two concepts are now integrated, you would simply register a DecimalSerializer globally with it&apos;s representation set to string and all decimals would get stored as a string because the serializer itself was configured that way.&lt;/p&gt;</comment>
                            <comment id="592723" author="nikkilocke" created="Thu, 22 May 2014 08:04:22 +0000"  >&lt;p&gt;Please could you explain what you mean, specifically how to set the default serialisation type for all decimals to double, and which version of the library is required for it to work?&lt;/p&gt;</comment>
                            <comment id="592086" author="craiggwilson" created="Wed, 21 May 2014 19:32:50 +0000"  >&lt;p&gt;This works based on how we simply refactored the code for serialization.&lt;/p&gt;</comment>
                            <comment id="520397" author="rstam" created="Thu, 20 Mar 2014 21:22:34 +0000"  >&lt;p&gt;Conventions are only used with classes that will be serialized using a BsonClassMapSerializer.&lt;/p&gt;

&lt;p&gt;In 3.0 we are planning to make serialization options a property of the serializer itself. So in 3.0 you will be able to instantiate an instance of DecimalSerializer with the Representation set to BsonType.Double and register it as the serializer to use for decimals everywhere.&lt;/p&gt;</comment>
                            <comment id="505586" author="nikkilocke" created="Wed, 26 Feb 2014 13:00:37 +0000"  >&lt;p&gt;Example class to illustrate the problem:&lt;/p&gt;

&lt;p&gt;class Test {&lt;br/&gt;
    public Test() &lt;/p&gt;
{
        Array = new decimal[2];
        Array[0] = 2;
        Array[1] = 3;
        Dict = new Dictionary&amp;lt;string, decimal[]&amp;gt;();
        Dict[&quot;test&quot;] = Array;
        Dict2 = new SortedDictionary&amp;lt;string, decimal []&amp;gt;();
        Dict2[&quot;test&quot;] = Array;
        Dict3 = new DerivedDictionary();
        Dict3[&quot;test&quot;] = Array;
        Dict4 = new Dictionary&amp;lt;string, DerivedDictionary&amp;gt;();
        Dict4[&quot;test&quot;] = Dict3;
    }

&lt;p&gt;    public decimal Field = 1;&lt;/p&gt;

&lt;p&gt;    public decimal [] Array;&lt;/p&gt;

&lt;p&gt;    public Dictionary&amp;lt;string, decimal[]&amp;gt; Dict;&lt;/p&gt;

&lt;p&gt;    public SortedDictionary&amp;lt;string, decimal[]&amp;gt; Dict2;&lt;/p&gt;

&lt;p&gt;    public DerivedDictionary Dict3;&lt;/p&gt;

&lt;p&gt;    public Dictionary&amp;lt;string, DerivedDictionary&amp;gt; Dict4;&lt;/p&gt;

&lt;p&gt;    public class DerivedDictionary : Dictionary&amp;lt;string, decimal[]&amp;gt; {&lt;br/&gt;
    }&lt;br/&gt;
}&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|hrggi7:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9586</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                    <customfield id="customfield_10557" key="com.pyxis.greenhopper.jira:gh-sprint">
                        <customfieldname>Sprint</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue id="131">Sprint 2</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>