<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:38:27 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-2382] Unmarshaling BSON into a struct with interface fields containing concrete value types doesn&apos;t work as expected.</title>
                <link>https://jira.mongodb.org/browse/GODRIVER-2382</link>
                <project id="14289" key="GODRIVER">Go Driver</project>
                    <description>&lt;p&gt;From a &lt;a href=&quot;https://www.mongodb.com/community/forums/t/unmarshalbson-having-different-behavior-than-unmarshaljson-and-erroring-where-it-should-not/157649&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;forum post&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Hi there,&lt;/p&gt;

&lt;p&gt;I am trying to work with an interface{}&lt;/p&gt;

&lt;p&gt;I have an object of type foo containing an interface ActivationInterface ; this object is persisted and I have trouble fetching it back, as the underlying type of the inner object is not known.&lt;/p&gt;

&lt;p&gt;I implemented UnmarshalBSON as follow without success ; it seems that even after setting the concrete type of the interface, the unmarshaler still does now the underlying type and I still get the error: error decoding key act: no decoder found for main.ActivationInterface&lt;/p&gt;

&lt;p&gt;I tried replacing everything BSON related by JSON ; and it works.&lt;br/&gt;
Here are both examples:&lt;br/&gt;
Erroring UnmarshalBSON: &lt;a href=&quot;https://go.dev/play/p/bHMy6-ZLsYQ&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Go Playground - The Go Programming Language&lt;/a&gt;&lt;br/&gt;
Almost the same code, but woking using UnmarshallJSON: &lt;a href=&quot;https://go.dev/play/p/V5HLrQ_-ls3&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Go Playground - The Go Programming Language&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Do you have any idea on what is happening ?&lt;br/&gt;
Thanks !&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;tldr; Unmarshaling JSON into an instance of a struct with an empty interface field that has a value assigned to it unmarshals into the assigned value correctly. The BSON unmarshaler ignores the assigned value and only considers the field type in the struct definition, resulting into an unmarshal error.&lt;/p&gt;

&lt;p&gt;E.g.&lt;/p&gt;
&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;type foo struct {&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;	Val interface{}&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;a := foo{Val: &quot;&quot;}&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;b := foo{Val: 0}&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;// a and b should unmarshal using the type of the value assigned to Val, not interface{}&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;See &lt;a href=&quot;https://github.com/mongodb/mongo-go-driver/blob/94985f51e6e51bd8b05d5df04c60db36dfb99e61/bson/bsoncodec/struct_codec.go#L438&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;StructCodec.describeStruct&lt;/a&gt;, which takes a &lt;tt&gt;reflect.Type&lt;/tt&gt; instead of a &lt;tt&gt;reflect.Value&lt;/tt&gt;, meaning it can&apos;t access the original value that might have additional type information. Additionally, the struct description caching (see &lt;a href=&quot;https://github.com/mongodb/mongo-go-driver/blob/94985f51e6e51bd8b05d5df04c60db36dfb99e61/bson/bsoncodec/struct_codec.go#L442&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;here&lt;/a&gt;) complicates getting different values for the fields of the same struct type.&lt;/p&gt;</description>
                <environment></environment>
        <key id="2024522">GODRIVER-2382</key>
            <summary>Unmarshaling BSON into a struct with interface fields containing concrete value types doesn&apos;t work as expected.</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="10300" iconUrl="https://jira.mongodb.org/images/icons/priorities/medium.svg">Unknown</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="3">Duplicate</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="matt.dale@mongodb.com">Matt Dale</reporter>
                        <labels>
                            <label>neweng</label>
                    </labels>
                <created>Wed, 13 Apr 2022 17:37:26 +0000</created>
                <updated>Fri, 14 Oct 2022 22:18:18 +0000</updated>
                            <resolved>Fri, 14 Oct 2022 22:18:18 +0000</resolved>
                                                                                        <votes>1</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="4904853" author="JIRAUSER1259527" created="Fri, 14 Oct 2022 22:18:18 +0000"  >&lt;p&gt;Duplicates &lt;a href=&quot;https://jira.mongodb.org/browse/GODRIVER-1808&quot; title=&quot;Unmarshaling BSON into a struct with interface fields containing concrete value types doesn&amp;#39;t work as expected.&quot; class=&quot;issue-link&quot; data-issue-key=&quot;GODRIVER-1808&quot;&gt;GODRIVER-1808&lt;/a&gt;.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                            <outwardlinks description="duplicates">
                                        <issuelink>
            <issuekey id="1566070">GODRIVER-1808</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <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|i0a2jc:</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>