<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:35:30 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>[GODRIVER-1029] BSON marshaling does not know how to handle common Go patterns such as struct composition</title>
                <link>https://jira.mongodb.org/browse/GODRIVER-1029</link>
                <project id="14289" key="GODRIVER">Go Driver</project>
                    <description>&lt;p&gt;In Go, struct composition is extremely common. Embedding a struct into another struct is the only way we can achieve some level of subclassing and inheritance in the language.&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;It appears the BSON marshalers are not prepared to handle this at all. In most cases, the fields are just completely ignored. In other cases, it includes a hidden field name.&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;I expect the bson marshaller to handle structs in the same way as the Golang JSON marshaller. I have created a gist to express the JSON behavior&#160;&lt;a href=&quot;https://gist.github.com/qhenkart/2c4fd696d1450ac266a09d1c62d4f67a&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://gist.github.com/qhenkart/2c4fd696d1450ac266a09d1c62d4f67a&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;The exact same code with bson tags and the mongo library will be completely ignored by the bson marshaller. The final document that is inserted is simply empty. There are a lot of different variations of struct composition, and the BSON marshaller must know how to handle them.&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;Additionally, I recently tried extending primitive.ObjectId, to create a workaround on another issue I posted recently. I extended it as follows&lt;/p&gt;

&lt;p&gt;`type ObjectID struct { primitive.ObjectID}`&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;This allows me to overwrite or add methods to the class and inherit all of the behavior of the primitive.ObjectID. It works great except the BSON marshaller doesn&apos;t ignore it in this case. In this case it would insert something along the lines of&#160;&lt;/p&gt;

&lt;p&gt;`id: {objectId: ObjectId(&quot;&amp;lt;validobjectid&amp;gt;&quot;)}&lt;/p&gt;</description>
                <environment></environment>
        <key id="763127">GODRIVER-1029</key>
            <summary>BSON marshaling does not know how to handle common Go patterns such as struct composition</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="divjot.arora@mongodb.com">Divjot Arora</assignee>
                                    <reporter username="qhenkart@gmail.com">Quest Henkart</reporter>
                        <labels>
                            <label>mgocompat</label>
                    </labels>
                <created>Thu, 9 May 2019 10:06:53 +0000</created>
                <updated>Tue, 16 Nov 2021 16:58:51 +0000</updated>
                            <resolved>Thu, 27 Jun 2019 14:52:30 +0000</resolved>
                                                                    <component>BSON</component>
                                        <votes>0</votes>
                                    <watches>4</watches>
                                                                                                                <comments>
                            <comment id="2273943" author="divjot.arora" created="Thu, 6 Jun 2019 15:20:35 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=qhenkart&quot; class=&quot;user-hover&quot; rel=&quot;qhenkart&quot;&gt;qhenkart&lt;/a&gt; Our BSON machinery does not marshal or unmarshal private fields. For embedded structs, our default behavior is to include an extra key as the struct name and an embedded document as the value. If you do not want to include the extra key, you can specify the &lt;tt&gt;`bson:&quot;inline&quot;`&lt;/tt&gt; struct tag for embedded fields.&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_10857" key="com.pyxis.greenhopper.jira:gh-epic-link">
                        <customfieldname>Epic Link</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>GODRIVER-226</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hr77bj:</customfieldvalue>

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