<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 09:02:35 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-4636] Codec Support for any type of Map key</title>
                <link>https://jira.mongodb.org/browse/JAVA-4636</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;Currently, it seems that the default set of Codecs supports just `Map&amp;lt;String, Object&amp;gt;`. This is fine for many use cases, but there is often the use case to use any number of key types.&lt;/p&gt;

&lt;p&gt;Currently, I have a (most likely/ obviously) sub-optimal solution that looks like this: &lt;a href=&quot;https://stackoverflow.com/questions/67849754/mongodb-mapk-v-codec-maps-must-have-string-keys-fix&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://stackoverflow.com/questions/67849754/mongodb-mapk-v-codec-maps-must-have-string-keys-fix&lt;/a&gt; (not my code)&lt;/p&gt;

&lt;p&gt;This works &lt;em&gt;most&lt;/em&gt; of the time, but seems to hate `Map&amp;lt;ObjectId, *&amp;gt;` types.&lt;/p&gt;

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

&lt;p&gt;There should be a standardized codec that can handle any type of map.&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;</description>
                <environment></environment>
        <key id="2059224">JAVA-4636</key>
            <summary>Codec Support for any type of Map key</summary>
                <type id="2" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14711&amp;avatarType=issuetype">New Feature</type>
                                            <priority id="10300" iconUrl="https://jira.mongodb.org/images/icons/priorities/medium.svg">Unknown</priority>
                        <status id="10038" iconUrl="https://jira.mongodb.org/images/icons/subtask.gif" description="">Backlog</status>
                    <statusCategory id="2" key="new" colorName="default"/>
                                    <resolution id="-1">Unresolved</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="contact@gjstewart.net">Greg Stewart</reporter>
                        <labels>
                    </labels>
                <created>Tue, 31 May 2022 22:53:24 +0000</created>
                <updated>Wed, 22 Jun 2022 18:26:45 +0000</updated>
                                                                            <component>POJO</component>
                                        <votes>1</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="4626639" author="ross@10gen.com" created="Mon, 20 Jun 2022 10:22:14 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=contact%40gjstewart.net&quot; class=&quot;user-hover&quot; rel=&quot;contact@gjstewart.net&quot;&gt;contact@gjstewart.net&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;Thanks for the ticket. I&apos;m glad you have a work around. Its an interesting problem as Bson requires keys to be Strings, so the issue is how to convert to strings in a meaningful way. Also, round tripping may be a requirement as well, and keeping the same types.&lt;/p&gt;

&lt;p&gt;I think a custom codec is possibly the best solution for now. We do have an annotation &lt;tt&gt;@BsonRepresentation&lt;/tt&gt; that was added to handle single types but it wouldn&apos;t be ideal for handling maps.&lt;/p&gt;

&lt;p&gt;I&apos;m going to put this ticket on the backlog for future consideration. If you have any extra feedback or usecases then please add to the ticket and that may help with the scheduling.&lt;/p&gt;

&lt;p&gt;Many thanks,&lt;/p&gt;

&lt;p&gt;Ross&lt;/p&gt;</comment>
                            <comment id="4608910" author="JIRAUSER1269884" created="Sat, 11 Jun 2022 15:12:38 +0000"  >&lt;p&gt;After some adjustment and debugging, I have a solution that should be adequate, but I haven&apos;t added all the class cases I have listed above. I am sure there is more to tweak for an &apos;official&apos; version, but here&apos;s what I got:&lt;/p&gt;

&lt;p&gt;Codec:&lt;br/&gt;
&lt;a href=&quot;https://github.com/Epic-Breakfast-Productions/OpenQuarterMaster/blob/a68718304e1cfa6a9b51d59dc9eefe339794f2a0/software/open-qm-base-station/src/main/java/com/ebp/openQuarterMaster/baseStation/mongoUtils/codecs/AnyMapCodec.java&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/Epic-Breakfast-Productions/OpenQuarterMaster/blob/a68718304e1cfa6a9b51d59dc9eefe339794f2a0/software/open-qm-base-station/src/main/java/com/ebp/openQuarterMaster/baseStation/mongoUtils/codecs/AnyMapCodec.java&lt;/a&gt;&lt;br/&gt;
Codec Provider:&lt;br/&gt;
&lt;a href=&quot;https://github.com/Epic-Breakfast-Productions/OpenQuarterMaster/blob/a68718304e1cfa6a9b51d59dc9eefe339794f2a0/software/open-qm-base-station/src/main/java/com/ebp/openQuarterMaster/baseStation/mongoUtils/AnyMapCodecProvider.java&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/Epic-Breakfast-Productions/OpenQuarterMaster/blob/a68718304e1cfa6a9b51d59dc9eefe339794f2a0/software/open-qm-base-station/src/main/java/com/ebp/openQuarterMaster/baseStation/mongoUtils/AnyMapCodecProvider.java&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="4588273" author="JIRAUSER1269884" created="Wed, 1 Jun 2022 21:18:08 +0000"  >&lt;p&gt;I&apos;ll add that the scope of &quot;any&quot; object should probably be limited to:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;all primitive-based (char, int, etc)&lt;/li&gt;
	&lt;li&gt;a selection of Java-util based objects
	&lt;ul&gt;
		&lt;li&gt;Date/ timestamps (new and old)&lt;/li&gt;
		&lt;li&gt;Url&apos;s/ URI&apos;s&lt;/li&gt;
		&lt;li&gt;Other, similar with simple to/from string methods&lt;/li&gt;
	&lt;/ul&gt;
	&lt;/li&gt;
	&lt;li&gt;Any Enum values&lt;/li&gt;
	&lt;li&gt;Bson&apos;s ObjectId&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Bonus points for being able to handle any class that we have a codec for already. Alternatively, could have a method for adding your own to/fromString methods for specific clases; something like `register(Class&amp;lt;T&amp;gt; clazz, Supplier&amp;lt;T&amp;gt; toStringMethod, Consumer&amp;lt;T&amp;gt; fromStringMethod)` (I think I am getting my java8 correct there)&lt;/p&gt;

&lt;p&gt;I would expect that the generated bson would be such that the keys in the map were searchable, with non-bson-equivalent values be turned to generic strings for the keys, rather than using a wrapping object to store the key alongside the data.&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|i0fvio:</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>