<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:52:52 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-700] Cannot Serialize/Deserialize ObjectId using Adobe BlazeDS(flex-messaging)</title>
                <link>https://jira.mongodb.org/browse/JAVA-700</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;Hello,&lt;/p&gt;

&lt;p&gt;I use Native Adobe BlazeDS Library used to serialize and deserialize AMF (Action Message Format) which can convert native ActionScript3/Flex objects to Java Objects. This serialization library looks for &quot;public&quot; non-transient fields in the object, recursively and transform them from AS/Java | Java/As. However, in the ObjectId class, the &quot;_inc&quot;, &quot;_time&quot; and &quot;_machine&quot; fields are using default access modifiers and are &quot;final int&quot;.&lt;/p&gt;

&lt;p&gt;In the ObjectId default constructor a new ID is generated : &lt;br/&gt;
/** Create a new object id.&lt;br/&gt;
 */&lt;br/&gt;
public ObjectId(){&lt;br/&gt;
	_time = (int) (System.currentTimeMillis() / 1000);&lt;br/&gt;
	_machine = _genmachine;&lt;br/&gt;
	_inc = _nextInc.getAndIncrement();&lt;br/&gt;
	_new = true;&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;Doing so, BlazeDS creates a new ObjectId on deserialization and cannot modifier furthermore the &quot;final int&quot;. The ObjectId is a new one.&lt;/p&gt;

&lt;p&gt;**********************************************************&lt;br/&gt;
Serializing ObjectId...&lt;br/&gt;
Before serialization : time &apos;10000&apos;, machine &apos;20&apos;, inc &apos;30&apos;, _id &apos;0000000a000000140000001e&apos;&lt;br/&gt;
Deserialized ObjectId...&lt;br/&gt;
After serialization : time &apos;1353591710000&apos;, machine &apos;1079454374&apos;, inc &apos;-693442528&apos;, _id &apos;50ae2b9e40572aa6d6aae820&apos;&lt;br/&gt;
**********************************************************&lt;/p&gt;

&lt;p&gt;I&apos;ve modified your ObjectId class and rebuilt it with &quot;public int _inc&quot; instead of &quot;final int _inc&quot; and it now works properly. However, I understand that it breaks your class encapsulation.&lt;/p&gt;

&lt;p&gt;**********************************************************&lt;br/&gt;
Serializing ObjectId...&lt;br/&gt;
Before serialization : time &apos;10000&apos;, machine &apos;20&apos;, inc &apos;30&apos;, _id &apos;0000000a000000140000001e&apos;&lt;br/&gt;
Deserialized ObjectId...&lt;br/&gt;
After serialization : time &apos;10000&apos;, machine &apos;20&apos;, inc &apos;30&apos;, _id &apos;0000000a000000140000001e&apos;&lt;br/&gt;
**********************************************************&lt;/p&gt;


&lt;p&gt;I would like to know if you plan on something regarding this class. Would it be possible to :&lt;/p&gt;

&lt;p&gt;1 - make fields public instead of package-protected final?&lt;br/&gt;
2 - would it be possible to leave the constructor empty and add a new &quot;.newId()&quot; method?&lt;br/&gt;
3 - Is it a good idea to create a ObjectId2 class that encapsulates an ObjectId and a public String so that the library BlazeDS can properly serialize/deserialize the String and create the ObjectId using the String? What would be the impact in the database PrimaryKey?&lt;br/&gt;
4 - Do you have any better idea?&lt;/p&gt;


&lt;p&gt;I&apos;ve attached a demo with the native library and the modified one.&lt;/p&gt;

&lt;p&gt;Thanks for your time.&lt;/p&gt;

&lt;p&gt;Daniel Marcotte&lt;/p&gt;</description>
                <environment>Windows 2008 Server&lt;br/&gt;
Java JDK 7u07&lt;br/&gt;
MongoDB Driver : mongo-2.9.3.jar&lt;br/&gt;
Adobe BlazeDS : flex-messaging-core.jar</environment>
        <key id="57224">JAVA-700</key>
            <summary>Cannot Serialize/Deserialize ObjectId using Adobe BlazeDS(flex-messaging)</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="-1">Unassigned</assignee>
                                    <reporter username="dmarcotte">Daniel Marcotte</reporter>
                        <labels>
                            <label>ObjectId</label>
                            <label>adobe</label>
                            <label>blazeds</label>
                            <label>deserialization</label>
                            <label>driver</label>
                            <label>serialization</label>
                    </labels>
                <created>Thu, 22 Nov 2012 13:44:48 +0000</created>
                <updated>Tue, 25 Jun 2013 11:07:42 +0000</updated>
                            <resolved>Sun, 25 Nov 2012 23:06:44 +0000</resolved>
                                    <version>2.9.1</version>
                    <version>2.9.2</version>
                    <version>2.9.3</version>
                                                    <component>API</component>
                    <component>Codecs</component>
                                        <votes>1</votes>
                                    <watches>3</watches>
                                                                                                                <comments>
                            <comment id="196967" author="jeff.yemin" created="Fri, 23 Nov 2012 00:51:10 +0000"  >&lt;p&gt;Hi Daniel,&lt;/p&gt;

&lt;p&gt;I definitely want to leave the ObjectId class immutable, which means that all fields are final and need to be initialized in every constructor.  This insures that ObjectId instances are thread-safe and don&apos;t require any further synchronization.&lt;/p&gt;

&lt;p&gt;I think your best bet is to something like option 3 in the description.  Just make sure that you don&apos;t try to insert instances of ObjectId2 into Mongo.  You&apos;ll have to convert to ObjectId before insertion.&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                            <attachment id="21916" name="object_id_serialization_example.rar" size="2156399" author="dmarcotte" created="Thu, 22 Nov 2012 13:44:48 +0000"/>
                    </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|hrkphz:</customfieldvalue>

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