<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 09:01:10 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>[JAVA-4073] ObjectId not deserializing from json to its original value</title>
                <link>https://jira.mongodb.org/browse/JAVA-4073</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;I have a rest api which reads a document from mongo collection and one more API which adds/updates&#160;the document into&#160;the same collection.&lt;/p&gt;

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

&lt;p&gt;I have upgraded project&#160;to Spring-data-mongo 2.4.3 and now I have a problem.&lt;/p&gt;

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

&lt;p&gt;Below is Objectid for a row&lt;/p&gt;

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

&lt;p&gt;57d7171c02666d68cb2ec50b&lt;/p&gt;

&lt;p&gt;It&#160;translates&#160;to&#160;the corresponding json&lt;/p&gt;

{ &quot;timestamp&quot;: 1473713948, &quot;counter&quot;: 3065099, &quot;randomValue1&quot;: 157293, &quot;randomValue2&quot;: 26827 }

&lt;p&gt;and in API response I get below output&lt;/p&gt;

&lt;p&gt;{{ &quot;id&quot;: &lt;/p&gt;
{ &quot;timestamp&quot;: 1473713948, &quot;counter&quot;: 3065099, &quot;randomValue1&quot;: 157293, &quot;randomValue2&quot;: 26827 }
&lt;p&gt;,&lt;br/&gt;
 &quot;product&quot;: &quot;ABCD&quot;}&lt;/p&gt;

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

&lt;p&gt;Now if I update&#160;the product name&#160;to something else and use&#160;the second API&#160;to post&#160;the same content,&#160;&lt;b&gt;instead of updating&#160;the row, it is creating&#160;a different row.&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;*{{ &quot;id&quot;: &lt;/p&gt;
{ &quot;timestamp&quot;: 1473713948, &quot;counter&quot;: 3065099, &quot;randomValue1&quot;: 157293, &quot;randomValue2&quot;: 26827 }
&lt;p&gt;,*&lt;br/&gt;
 &lt;b&gt;&quot;product&quot;: &quot;EFGH&quot;}&lt;/b&gt;&lt;/p&gt;

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

&lt;p&gt;&lt;b&gt;Now&lt;/b&gt;&#160;&lt;b&gt;the new ObjectId for new row is below&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;57d7171c07430961eb07d9e2&lt;/b&gt;&lt;/p&gt;

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

&lt;p&gt;&lt;b&gt;In&lt;/b&gt;&lt;b&gt;tres&lt;/b&gt;&lt;b&gt;tingl bo&lt;/b&gt;&lt;b&gt;th&lt;/b&gt;&#160;&lt;b&gt;transla&lt;/b&gt;&lt;b&gt;tes&lt;/b&gt;&#160;&lt;b&gt;to&lt;/b&gt;&#160;&lt;b&gt;the same json as above.&lt;/b&gt;**&lt;/p&gt;

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

&lt;p&gt;&lt;b&gt;this is happening in la&lt;/b&gt;&lt;b&gt;tes&lt;/b&gt;&lt;b&gt;t version of spring-da&lt;/b&gt;&lt;b&gt;ta-mongo only.... earlier version 2.0.1 is good.&lt;/b&gt;****&lt;/p&gt;

&lt;p&gt;&lt;b&gt;No&lt;/b&gt;&lt;b&gt;t sure if&lt;/b&gt;&#160;&lt;b&gt;the issue is wi&lt;/b&gt;&lt;b&gt;th BSON ID, or JACKSON or MONGO DRIVER i&lt;/b&gt;&lt;b&gt;tself.&lt;/b&gt;****&lt;/p&gt;

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

&lt;p&gt;&lt;b&gt;Please assis&lt;/b&gt;&lt;b&gt;t us on&lt;/b&gt;&#160;&lt;b&gt;this issue.&lt;/b&gt;****&lt;/p&gt;

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

&lt;p&gt;&#160;&lt;/p&gt;</description>
                <environment></environment>
        <key id="1651018">JAVA-4073</key>
            <summary>ObjectId not deserializing from json to its original value</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="13202">Works as Designed</resolution>
                                        <assignee username="ross@mongodb.com">Ross Lawley</assignee>
                                    <reporter username="lingared@adobe.com">Subash Lingaredd</reporter>
                        <labels>
                    </labels>
                <created>Wed, 17 Mar 2021 09:08:33 +0000</created>
                <updated>Fri, 27 Oct 2023 13:20:57 +0000</updated>
                            <resolved>Thu, 18 Mar 2021 15:10:57 +0000</resolved>
                                                                    <component>BSON</component>
                    <component>POJO</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="3671293" author="ross@10gen.com" created="Thu, 18 Mar 2021 15:10:45 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=lingared%40adobe.com&quot; class=&quot;user-hover&quot; rel=&quot;lingared@adobe.com&quot;&gt;lingared@adobe.com&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;Just to note we don&apos;t support Spring-data-mongo or Jackson. However, I have found a &lt;a href=&quot;https://stackoverflow.com/questions/14363555/spring-3-2-and-jackson-2-add-custom-object-mapper&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;stackoverflow&lt;/a&gt; post that provides an example of ObjectId serialization with Jackson.&lt;/p&gt;

&lt;p&gt;I&apos;m still unclear if the API that provides the JSON uses the same version of the Spring data as the API that consumes the JSON.&lt;/p&gt;

&lt;p&gt;I would advise you to use our MongoDB community portal, located &lt;a href=&quot;https://developer.mongodb.com/community/forums/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;here&lt;/a&gt; for this question. There maybe users that have had similar issues.&lt;/p&gt;

&lt;p&gt;All the best,&lt;/p&gt;

&lt;p&gt;Ross&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;</comment>
                            <comment id="3669444" author="JIRAUSER1259091" created="Wed, 17 Mar 2021 17:04:04 +0000"  >&lt;p&gt;Could u please provide us some working java example for below&#160;&lt;/p&gt;

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

&lt;p&gt;&lt;b&gt;If you can configure Jackson to use the&#160;&lt;tt&gt;ObjectId.toHexString()&lt;/tt&gt;&#160;method and&#160;&lt;tt&gt;ObjectId(final String hexString)&lt;/tt&gt;&#160;constructor, then that would be a better approach as it relies on the public API.&lt;/b&gt;&lt;/p&gt;

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

&lt;p&gt;&lt;b&gt;I checked a few bu&lt;/b&gt;&lt;b&gt;t no success.&lt;/b&gt;**&lt;/p&gt;

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

&lt;p&gt;&lt;b&gt;S&lt;/b&gt;&lt;b&gt;till I am in a s&lt;/b&gt;&lt;b&gt;ta&lt;/b&gt;&lt;b&gt;te of confusion whe&lt;/b&gt;&lt;b&gt;ther&lt;/b&gt;&#160;&lt;b&gt;this is a mongo-java-driver version change issue or a Jackson issue because of&lt;/b&gt;&#160;&lt;b&gt;this version change.&lt;/b&gt;****&lt;/p&gt;</comment>
                            <comment id="3668661" author="ross@10gen.com" created="Wed, 17 Mar 2021 12:56:44 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=lingared%40adobe.com&quot; class=&quot;user-hover&quot; rel=&quot;lingared@adobe.com&quot;&gt;lingared@adobe.com&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;The &lt;tt&gt;ObjectId&lt;/tt&gt; class was brought up to &lt;a href=&quot;https://github.com/mongodb/specifications/blob/master/source/objectid.rst&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;specification&lt;/a&gt; in &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-2916&quot; title=&quot;Implement ObjectID spec&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-2916&quot;&gt;&lt;del&gt;JAVA-2916&lt;/del&gt;&lt;/a&gt;. This is when the change happened to the internal implementation details of the &lt;tt&gt;ObjectId&lt;/tt&gt; class. It looks like the way in which you are using Jackson is causing these internal private fields to be serialized. This is leaking the internal implementation details of the ObjectId class! Which generally should be avoided as it risks compatibility issues like you describe.&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;We suspect this is happening due to a change in machineIdentfier and processIdentifier fields. All the old rows are serialized with these fields using 3.6.3 and now we are deserializing with 4.1.1 we suspect the deserializer is not able to find those machineIdentifier and processIdentifier fields and instead it finds randomValue1 and randomValue2 fields and hence it declares it a new id and inserts it.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;This shouldn&apos;t be an issue if &lt;b&gt;both&lt;/b&gt; the provider and consumer of the Json use the same version of the Java driver underneath &lt;b&gt;and&lt;/b&gt; a serialization mechanism that &lt;em&gt;supports the 4.1.1 version of the ObjectId.&lt;/em&gt; I&apos;m not sure how Jackson deserializes into ObjectId classes. It should be noted that there is no constructor that takes &lt;tt&gt;ObjectId(final int timestamp, final int randomValue1, final short randomValue2, final int counter)&lt;/tt&gt; so using those values is not recommended. I&apos;m not sure how Jackson deserializes the json: {&quot;timestamp&quot;: 1473713948, &quot;counter&quot;: 3065099, &quot;randomValue1&quot;: 157293, &quot;randomValue2&quot;: 26827} into an ObjectId -&#160; so that should be investigated.&lt;/p&gt;

&lt;p&gt;If you can configure Jackson to use the &lt;tt&gt;ObjectId.toHexString()&lt;/tt&gt; method and &lt;tt&gt;ObjectId(final String hexString)&lt;/tt&gt; constructor, then that would be a better approach as it relies on the public API.&lt;/p&gt;

&lt;p&gt;Ross&lt;/p&gt;</comment>
                            <comment id="3668627" author="JIRAUSER1259091" created="Wed, 17 Mar 2021 12:30:08 +0000"  >&lt;p&gt;We use JACKSON for serializing and deserializing.&lt;/p&gt;</comment>
                            <comment id="3668615" author="JIRAUSER1259091" created="Wed, 17 Mar 2021 12:23:00 +0000"  >&lt;p&gt;Hi Ross,&lt;/p&gt;

&lt;p&gt;thanks for a quick response.&lt;/p&gt;

&lt;p&gt;Let me explain&#160;the chronology&lt;/p&gt;

&lt;p&gt;Earlier we were using Spring Data Mongo&#160;2.0.0.RELEASE and&#160;this has mongo-driver 3.6.3 installed. Everything was working fine and also in&#160;the above-mentioned&#160;scenario, the update operation will update&#160;the same row again and again (if it has an id field, the id field will do as our spring manages both id and _id)&lt;/p&gt;

&lt;p&gt;Now we are planning&#160;to move to Spring Data Mongo 2.4.3 and&#160;this has mongo-driver 4.1.1 installed with it. Here comes&#160;the problem,&#160;the same scenario explained above is now inserting n number of rows (for n number of updates on&#160;the same row with id field). Even&#160;the new rows are also behaving&#160;the same way.&lt;/p&gt;

&lt;p&gt;We suspect&#160;this is happening due&#160;to a change in machineIdentfier and processIdentifier fields. All&#160;the old rows are serialized with&#160;these fields using 3.6.3 and now we are deserializing with 4.1.1&#160; we suspect&#160;the deserializer is not able&#160;to find&#160;those machineIdentifier and processIdentifier fields and instead it finds randomValue1 and randomValue2 fields and hence it declares it a new id and inserts it.&lt;/p&gt;

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

&lt;p&gt;&lt;b&gt;We have&#160;tested it 3&#160;to 4&#160;times&#160;today with&#160;these&#160;two mongo-driver version and was able&#160;to replicate&#160;the issue.&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;the weird&#160;thing is&#160;the same happens again if I update&#160;the new row (which was created using 4.1.1) again.&lt;/b&gt;&lt;/p&gt;</comment>
                            <comment id="3668496" author="ross@10gen.com" created="Wed, 17 Mar 2021 10:59:25 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=lingared%40adobe.com&quot; class=&quot;user-hover&quot; rel=&quot;lingared@adobe.com&quot;&gt;lingared@adobe.com&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-3854&quot; title=&quot;ObjectId Serialization incompatibility&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-3854&quot;&gt;&lt;del&gt;JAVA-3854&lt;/del&gt;&lt;/a&gt; relates to JVM Object serialization and deserialization of the ObjectId class via &lt;tt&gt;writeReplace&lt;/tt&gt; and &lt;tt&gt;readResolve&lt;/tt&gt;.  &lt;/p&gt;

&lt;p&gt;The issue you describe seems to be related to JSON serialization and deserialization. Its unclear what mechanism you are using to serialize the ObjectId value (Jackson?).  I would recommend using &lt;a href=&quot;https://docs.mongodb.com/manual/reference/mongodb-extended-json/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;extended JSON&lt;/a&gt; for serializing bson documents. This is more robust as it doesn&apos;t rely on private internal implementation details of the class being serialized. That said both seem to produce the same data from the example given.&lt;/p&gt;

&lt;p&gt;Just to note the java driver will add a &lt;tt&gt;_id&lt;/tt&gt; field for a document if one is missing. I notice that you are passing &lt;tt&gt;id&lt;/tt&gt; fields and not &lt;tt&gt;_id&lt;/tt&gt; fields - could that be the issue? And the reason you are getting two inserts?&lt;/p&gt;

&lt;p&gt;Without more information regarding how you are using the driver and creating the values for the API - its difficult to understand what the actual issue is.   Ideally, a &lt;a href=&quot;https://stackoverflow.com/help/minimal-reproducible-example&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;minimal reproducible example&lt;/a&gt; would help as I could replicate the issue.&lt;/p&gt;

&lt;p&gt;Please use one of the support mechanisms listed above and support can be given there.  Feel free to post a link to this ticket and I can facilitate escalating your issue.&lt;/p&gt;

&lt;p&gt;All the best,&lt;/p&gt;

&lt;p&gt;Ross&lt;/p&gt;</comment>
                            <comment id="3668472" author="JIRAUSER1259091" created="Wed, 17 Mar 2021 10:41:04 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-3854&quot; class=&quot;external-link&quot; rel=&quot;nofollow&quot;&gt;https://jira.mongodb.org/browse/JAVA-3854&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;I see a link&#160;to&#160;this. Please let us know how should we be backward compatible....&lt;/p&gt;</comment>
                            <comment id="3668444" author="ross@10gen.com" created="Wed, 17 Mar 2021 10:21:12 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=lingared%40adobe.com&quot; class=&quot;user-hover&quot; rel=&quot;lingared@adobe.com&quot;&gt;lingared@adobe.com&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;Thank you for reaching out. As this sounds like a support issue, I wanted to give you some resources to get this question answered more quickly:&lt;/p&gt;

&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;Our MongoDB support portal, located at &lt;a href=&quot;https://support.mongodb.com/welcome&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;support.mongodb.com&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;Our MongoDB community portal, located &lt;a href=&quot;https://developer.mongodb.com/community/forums/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;here&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;If you are an Atlas customer, there is free support offered 24/7 in the lower right hand corner of the UI&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Just in case you have already opened a support case and are not receiving sufficient help, please let me know and I can facilitate escalating your issue.&lt;/p&gt;

&lt;p&gt;All the best,&lt;/p&gt;

&lt;p&gt;Ross Lawley&lt;/p&gt;</comment>
                            <comment id="3668411" author="JIRAUSER1259091" created="Wed, 17 Mar 2021 09:27:26 +0000"  >&lt;p&gt;Earlier our json was like below&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;
{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&quot;timestamp&quot;:&#160;1473713948,
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&quot;counter&quot;:&#160;3065099,
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&quot;machineIdentifier&quot;:&#160;157293,
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&quot;processIdentifier&quot;:&#160;26827
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}
&lt;p&gt;Are issues because of change in field names for machineIdentifier and processIdentifier in new version?&lt;/p&gt;</comment>
                            <comment id="3668401" author="JIRAUSER1259091" created="Wed, 17 Mar 2021 09:20:11 +0000"  >&lt;p&gt;Class we use for Mongo is MongoOperations&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;</comment>
                            <comment id="3668400" author="JIRAUSER1259091" created="Wed, 17 Mar 2021 09:19:48 +0000"  >&lt;p&gt;I am using SAVE method which inserts if no id is present and updates if&#160;there is an existing id field.&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|hyl1pr:</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>