<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:51:51 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-254] Converting arrays of embedded documents to custom objects</title>
                <link>https://jira.mongodb.org/browse/JAVA-254</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;DBCollection.setObjectClass() and DBCollection.setInternalClass() offer a convinient way to convert DBObjects to custom objects without using reflection. &lt;/p&gt;

&lt;p&gt;However there is no proper way of converting DBObjects contained in arrays to custom objects.  This is due to the way the driver retrieves &quot;internal classes&quot; by path. &lt;/p&gt;

&lt;p&gt;For instance, having:&lt;/p&gt;

&lt;p&gt;public class Question implements DBObject {&lt;br/&gt;
    /* ... */&lt;br/&gt;
    public List&amp;lt;Answer&amp;gt; answers;&lt;br/&gt;
} &lt;/p&gt;

&lt;p&gt;public class Answer implements DBObject {&lt;br/&gt;
    /* ... */&lt;br/&gt;
} &lt;/p&gt;

&lt;p&gt;The way to convert &quot;answers&quot; array items to Answer instances is as follows:&lt;/p&gt;

&lt;p&gt;collection.setInternalClass(&quot;answers.0&quot;, Answer.class);&lt;br/&gt;
collection.setInternalClass(&quot;answers.1&quot;, Answer.class);&lt;br/&gt;
collection.setInternalClass(&quot;answers.2&quot;, Answer.class);&lt;br/&gt;
and so on...&lt;/p&gt;

&lt;p&gt;it would be nice to have a way of setting a custom class for all items inside an array? Maybe using setInternalClass or a new method:&lt;/p&gt;

&lt;p&gt;collection.setInternalClass(&quot;answers.$&quot;, Answer.class); &lt;br/&gt;
collection.setCollectionItemClass(&quot;answers&quot;, Answer.class); &lt;/p&gt;
</description>
                <environment></environment>
        <key id="14197">JAVA-254</key>
            <summary>Converting arrays of embedded documents to custom objects</summary>
                <type id="2" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14711&amp;avatarType=issuetype">New Feature</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="javierferrero">Javier Ferrero</reporter>
                        <labels>
                    </labels>
                <created>Tue, 11 Jan 2011 17:42:57 +0000</created>
                <updated>Tue, 31 Mar 2015 20:09:57 +0000</updated>
                            <resolved>Tue, 25 Jun 2013 17:06:04 +0000</resolved>
                                    <version>2.4</version>
                                    <fixVersion>3.0.0</fixVersion>
                                    <component>API</component>
                                        <votes>6</votes>
                                    <watches>6</watches>
                                                                                                                <comments>
                            <comment id="869476" author="jeff.yemin" created="Tue, 31 Mar 2015 20:09:57 +0000"  >&lt;p&gt;Closing all resolved 3.0.0 issues, as 3.0.0 has been tagged and released.&lt;/p&gt;</comment>
                            <comment id="348736" author="auto" created="Thu, 30 May 2013 11:42:51 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;username&apos;: u&apos;jyemin&apos;, u&apos;name&apos;: u&apos;Jeff Yemin&apos;, u&apos;email&apos;: u&apos;jeff.yemin@10gen.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-254&quot; title=&quot;Converting arrays of embedded documents to custom objects&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-254&quot;&gt;&lt;del&gt;JAVA-254&lt;/del&gt;&lt;/a&gt;: DBCollection.setInternalClass works with arrays.  The fix is in DBObjectSerializer.&lt;br/&gt;
Branch: 3.0.x&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/commit/633dff2bdc17f7e567b94a5c82eeffb815220f30&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/633dff2bdc17f7e567b94a5c82eeffb815220f30&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="278455" author="jeff.yemin" created="Thu, 28 Feb 2013 20:50:54 +0000"  >&lt;p&gt;Sorry for the lack of response.  This will be part of the 3.0 release.  Until then, have you considered using an ODM like Morphia or Spring Data MongoDB, which provide much more functionality than this?&lt;/p&gt;</comment>
                            <comment id="278448" author="mbriskar" created="Thu, 28 Feb 2013 20:42:32 +0000"  >&lt;p&gt;It is quite a time since last reply and still with no update. It would be good to give us some information about current status so we would know what to expect.&lt;/p&gt;

&lt;p&gt;Thanks, &lt;br/&gt;
Mat&lt;/p&gt;</comment>
                            <comment id="180008" author="leif" created="Mon, 29 Oct 2012 11:21:35 +0000"  >&lt;p&gt;Have there been any updates on this issue?  I provided a patch over a year and a half ago to fix the problem.  But there are still no updates.&lt;/p&gt;

&lt;p&gt;We are fine with another solution if it exists, but we need a way to do this and would prefer not having to keep patching new driver versions &lt;img class=&quot;emoticon&quot; src=&quot;https://jira.mongodb.org/images/icons/emoticons/wink.png&quot; height=&quot;16&quot; width=&quot;16&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;

&lt;p&gt;Thanks,&lt;br/&gt;
Leif&lt;/p&gt;</comment>
                            <comment id="64116" author="leif" created="Wed, 2 Nov 2011 04:54:17 +0000"  >&lt;p&gt;I would also love to see this make it into a regular release.  We have been live with our patched version for several months and it has been working great.   We of course want to stick with the core Mongo driver as much as possible to make sure we don&apos;t go in a direction that leads to a dead end for us.&lt;/p&gt;</comment>
                            <comment id="64015" author="javierferrero" created="Tue, 1 Nov 2011 18:11:25 +0000"  >&lt;p&gt;Any plan to include this in a next release? Honestly, I think a document oriented storage should be able to work with lists of internal documents easily.&lt;/p&gt;</comment>
                            <comment id="27517" author="leif" created="Fri, 1 Apr 2011 06:45:34 +0000"  >&lt;p&gt;Patches to implement wildcard class mapping.  And it even includes full tests!!&lt;/p&gt;</comment>
                            <comment id="27516" author="leif" created="Fri, 1 Apr 2011 06:42:46 +0000"  >&lt;p&gt;This is also a big deal for us.  I had come up with the exact same temporary workaround before being pointed to this issue.&lt;/p&gt;

&lt;p&gt;The best way to elevate this is to implement it so I have done so.  I will attache two diffs for DBCollection.java and DBCollectionTest.java in a moment.&lt;/p&gt;

&lt;p&gt;The way I implemented it will work almost exactly the same as now unless setInternalClass is called with a value that has one or more wildcards.  In that case, when getInternalClass is called we have to iterate over all the registered mappings and do some wildcard matching.   This is still fairly fast.  It should not cause problems for existing applications as it only happens if the mappings were registered with wildcards.  It should be fast even when used because most collections only have a handful mappings in the first place.&lt;/p&gt;

&lt;p&gt;The patch will break up a name into an array of fields, separating them by &quot;.&quot;.   An individual wildcard can only match a full field name.   There are two wildcards. &quot;${*}&quot; will match any field name.  &quot;${n}&quot; will only match field names that are 100% made up of digits.&lt;/p&gt;

&lt;p&gt;So &quot;groups.${n}&quot; can be used to match &quot;groups.0&quot;, &quot;groups.1&quot;, etc.  But it will not match &quot;groups.foobar&quot;.&lt;/p&gt;

&lt;p&gt;Please let me know if this patch is acceptable or if you would like to change the format of the wildcards.  We will use the patched version for now, but would of course like to get back to using a standard released jar.&lt;/p&gt;

&lt;p&gt;Thanks for the great product!&lt;br/&gt;
Leif&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                            <attachment id="11219" name="DBCollection.java.diff" size="2808" author="leif" created="Fri, 1 Apr 2011 06:45:34 +0000"/>
                            <attachment id="11220" name="DBCollectionTest.java.diff" size="2267" author="leif" created="Fri, 1 Apr 2011 06:45:34 +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|hrhch3:</customfieldvalue>

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