<!-- 
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-855] Interface to allow control of object serialization</title>
                <link>https://jira.mongodb.org/browse/CSHARP-855</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;A suggestion.&lt;/p&gt;

&lt;p&gt;Provide a pre-defined C# interface to control whether entire object instances should be serialized (e.g. IControlledSerialization).&lt;/p&gt;

&lt;p&gt;I have many objects that are part of documents that get saved to Mongo.  Very often, I will not want to serialize that object at all, depending upon conditions within that object instance.    Rather than having to write separate ShouldSerialize&lt;span class=&quot;error&quot;&gt;&amp;#91;PropertyName&amp;#93;&lt;/span&gt; for each field in which that object appears, it would be simpler if the object could determine for itself whether it should be persisted. &lt;/p&gt;

&lt;p&gt;I have written a custom convention to implement this scheme, but it seems like it may be of more general use to the user community, and would be pretty simple to impement:&lt;/p&gt;

&lt;p&gt;public interface IControlledSerialization&lt;br/&gt;
{&lt;br/&gt;
    bool ShouldSerialize();&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;Classes that  have consistent criteria for serialization can then implement this interface, and use whatever criteria are appropriate for the action.&lt;/p&gt;

&lt;p&gt;If the interface (and the corresponding convention) were built into the driver, I think it would be useful to many.&lt;/p&gt;</description>
                <environment>All</environment>
        <key id="96127">CSHARP-855</key>
            <summary>Interface to allow control of object serialization</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</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>
                    </labels>
                <created>Tue, 29 Oct 2013 03:56:15 +0000</created>
                <updated>Mon, 11 Mar 2019 18:45:02 +0000</updated>
                            <resolved>Mon, 6 Apr 2015 20:20:31 +0000</resolved>
                                    <version>1.8.3</version>
                                                    <component>Serialization</component>
                                        <votes>0</votes>
                                    <watches>1</watches>
                                                                                                                <comments>
                            <comment id="448766" author="craiggwilson" created="Wed, 30 Oct 2013 14:06:47 +0000"  >&lt;p&gt;Certainly makes sense.  As you have written a convention to do this already, I guess all you are stating is that you would like this to be built-in to the driver, The downside to this, of course, that now your objects have a dependency on MongoDB where-as they may not have previously.  The way you have done it, you can define whatever interface you want and hook it up.&lt;/p&gt;

&lt;p&gt;We&apos;ll leave this ticket open, but not schedule it for implementation until we have talked it through.  Thanks for your input.&lt;/p&gt;</comment>
                            <comment id="448583" author="curt" created="Wed, 30 Oct 2013 00:21:40 +0000"  >&lt;p&gt;Craig -&lt;/p&gt;

&lt;p&gt;I think you misunderstood what I was suggesting.&lt;/p&gt;

&lt;p&gt;In my business object model, there are many (many, many!) constituent objects which carry optional data chunks (each of which is represented by a specialized class).   In such cases, it often worked out more cleanly to have those sub-objects determine for themselves whether they should be serialized--obviating the necessity of defining individual ShouldSerialiseXXX methods for individual properties on each the master objects in which they occur.&lt;/p&gt;

&lt;p&gt;I&apos;ve worked this out by defining a simple, optional, interface I can affiliate with such subobject classes.    The interface can let the object decide whether it should be serialized at all, rather than the owning object deciding on a field-by-field basis.&lt;/p&gt;

&lt;p&gt;As a concrete example, in the business classes I&apos;m writing, master objects have a complex &quot;Provenance&quot; object when the data came from an outside system.    Almost every master object type has a provenence field (or collection of them), so they probably occur within twenty different master classes that get serialized to Mongo. &lt;/p&gt;

&lt;p&gt; It is easier and cleaner, in this case, for the Provenance object to decide whether it should be serialized than implementing twenty or more ShouldSerializeXXX methods in each of the master classes.    It turned out to be pretty simple to implement, and I thought that providing a native Interface and convention for doing this would be something helpful to the community.&lt;/p&gt;

&lt;p&gt;Does this make sense to you?&lt;/p&gt;

&lt;p&gt;Thanks again for your quick response.&lt;/p&gt;

&lt;p&gt;Curt&lt;/p&gt;</comment>
                            <comment id="448085" author="craiggwilson" created="Tue, 29 Oct 2013 12:43:28 +0000"  >&lt;p&gt;The documentation here (&lt;a href=&quot;http://docs.mongodb.org/ecosystem/tutorial/serialize-documents-with-the-csharp-driver/#ignoring-a-member-based-on-a-shouldserializexyz-method&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/#ignoring-a-member-based-on-a-shouldserializexyz-method&lt;/a&gt;) indicates how to do this.  You can provide a ShouldSerializeXXX method where XXX is the name of your member.  Inside it, you can do anything you want and the results of this method will instruct the serialization infrastructure on whether or not to serialize that particular member.&lt;/p&gt;

&lt;p&gt;Craig&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|hs0tbr:</customfieldvalue>

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