<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:38:01 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-854] Implementing custom simple mapping for object types</title>
                <link>https://jira.mongodb.org/browse/CSHARP-854</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;I would like to provide simplified BSON mappings for a number of business object types (I&apos;ll provide some concrete examples further down).&lt;/p&gt;

&lt;p&gt;I will be storing millions of record of very complex business objects, for which many custom sub-objects have been designed.   Many of them can render as a simple string (and load as well), but because &quot;String&quot; is a sealed type in C#, I cannot build them as descendants of a string.&lt;/p&gt;

&lt;p&gt;For compactness, clarity, and ease of querying, I would like them to render into BSON as a simple string.   I have searched the documentation, newsgroups, and other resources, for examples of custom class mappings, but have not found sufficiently appropriate documentation or examples for me to build such a mapping.&lt;/p&gt;

&lt;p&gt;It might help to provide some simple examples:&lt;/p&gt;

&lt;p&gt;An timespan type:&lt;/p&gt;

&lt;p&gt;class TimeSpan&lt;br/&gt;
{&lt;br/&gt;
     private int _seconds;&lt;br/&gt;
    private string _toTimespanString()&lt;/p&gt;
    {
          ... implementation
    }
&lt;p&gt;    private void fromTimespanString(string s)&lt;/p&gt;
    {
               implementation...
    }

&lt;p&gt;     public string TimeString &lt;br/&gt;
    { &lt;br/&gt;
          get&lt;/p&gt;
{ return toTimespanString(); }
&lt;p&gt;          set&lt;/p&gt;
{ toTimespanString(value); }
&lt;p&gt;   }&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;In the above example, I would like to serialize the above type as a string (e.g. &quot;5h23m&quot;), and deserialize it from same.    The BSON serializer can do it, but it serializes as a Document, meaning that the value is buried with it.   &lt;/p&gt;

&lt;p&gt;I have a few classes that have a similar construct:  a business object is built around what is essentially a string value, in order to do conversion, calculation, validation, etc.   But when rendered, I&apos;d like them to appear in BSON documents as simple strings (examples include URIs, controlled vocabulary strings, and the TimeSpan indicated above).&lt;/p&gt;

&lt;p&gt;These objects may have many properties that are used for manipulation within a program, but only a single &lt;span class=&quot;error&quot;&gt;&amp;#91;BSonElement&amp;#93;&lt;/span&gt; string property that is used for setting and retrieving values.&lt;/p&gt;

&lt;p&gt;This might make a good generalized enhancement to the driver (e.g. allow a BSonStringRepresentation property as a convention), but I would like to know of any specific references / examples out there for doing such a custom BSON type mapping.   &lt;/p&gt;

&lt;p&gt;Can you help?&lt;/p&gt;

</description>
                <environment>All</environment>
        <key id="96122">CSHARP-854</key>
            <summary>Implementing custom simple mapping for object types</summary>
                <type id="3" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14718&amp;avatarType=issuetype">Task</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="curt">Curt Mayers</reporter>
                        <labels>
                            <label>BSON,</label>
                            <label>Type</label>
                            <label>mapping</label>
                            <label>question</label>
                    </labels>
                <created>Tue, 29 Oct 2013 02:29:48 +0000</created>
                <updated>Fri, 5 Apr 2019 13:59:05 +0000</updated>
                            <resolved>Thu, 20 Mar 2014 19:14:58 +0000</resolved>
                                    <version>1.8.3</version>
                                                    <component>Documentation</component>
                    <component>Feature Request</component>
                                        <votes>0</votes>
                                    <watches>1</watches>
                                                                                                                <comments>
                            <comment id="448079" author="craiggwilson" created="Tue, 29 Oct 2013 12:40:41 +0000"  >&lt;p&gt;Thanks for your question.  The documentation for serialization exists here: &lt;a href=&quot;http://docs.mongodb.org/ecosystem/tutorial/serialize-documents-with-the-csharp-driver/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://docs.mongodb.org/ecosystem/tutorial/serialize-documents-with-the-csharp-driver/&lt;/a&gt;.  It&apos;s long and involved.  The specific section you care about can be gotten to at this link:  &lt;a href=&quot;http://docs.mongodb.org/ecosystem/tutorial/serialize-documents-with-the-csharp-driver/#write-a-custom-serializer&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://docs.mongodb.org/ecosystem/tutorial/serialize-documents-with-the-csharp-driver/#write-a-custom-serializer&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Essentially, what you need to do is write an implementation of an IBsonSerializer.  Effectively, you&apos;ll take your TimeSpan class and convert it into a string on serialization and then parse that string on deserialization and convert it back to a TimeSpan. The best examples for how to do this would be to look in the source code at our existing implementations of serializers here: &lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/tree/master/MongoDB.Bson/Serialization/Serializers&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/tree/master/MongoDB.Bson/Serialization/Serializers&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Craig&lt;/p&gt;

</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                        <customfield id="customfield_10011" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Backwards Compatibility</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10038"><![CDATA[Fully Compatible]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <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|hrtuan:</customfieldvalue>

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