<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:57: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-2695] Add support for Map&lt;String, Object&gt; in PojoCodec</title>
                <link>https://jira.mongodb.org/browse/JAVA-2695</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;Hi guys,&lt;/p&gt;

&lt;p&gt;Our model consist of pojo classes containing Map&amp;lt;String,Object&amp;gt; properties field.&lt;br/&gt;
I try to user PojoCodec to save them in Mongo, however:&lt;/p&gt;

&lt;p&gt;1. In PojoCodecImpl, method addToCache determines the codec using type parameters: &quot;getCodecFromTypeData(typeData.getTypeParameters().get(1)));&quot; and saving the pojo results in &quot;CodecConfigurationException: Can&apos;t find a codec for class java.lang.Object&quot;.&lt;/p&gt;

&lt;p&gt;2. I tried converting the Map&amp;lt;String,Object&amp;gt; field to org.bson.Document field before saving the Pojo in Mongo. However, when PojoBuilderHeper.getTypeData() method is called with org.bson.Document parameter, it checks that it is a Map, but there are no type parameters - and it throws an Exception (TypeData:114: typeParameters.size() != 2).&lt;/p&gt;

&lt;p&gt;If I forget about Pojo and save new Document(map) or Document.parse(jsonStringRepresentationOfMap) - java mongo driver can recognize the types correctly (dates, numbers, etc.) and save them in database. But if this map is a field in a Pojo - I cannot save it.&lt;/p&gt;</description>
                <environment></environment>
        <key id="469868">JAVA-2695</key>
            <summary>Add support for Map&lt;String, Object&gt; in PojoCodec</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</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="ross@mongodb.com">Ross Lawley</assignee>
                                    <reporter username="aneta st&#281;pie&#324;">aneta st&#281;pie&#324;</reporter>
                        <labels>
                    </labels>
                <created>Fri, 8 Dec 2017 16:34:16 +0000</created>
                <updated>Thu, 16 Aug 2018 12:22:41 +0000</updated>
                            <resolved>Tue, 30 Jan 2018 15:10:10 +0000</resolved>
                                    <version>3.5.0</version>
                                    <fixVersion>3.7.0</fixVersion>
                                    <component>POJO</component>
                                        <votes>0</votes>
                                    <watches>4</watches>
                                                                                                                <comments>
                            <comment id="1977199" author="ross@10gen.com" created="Thu, 16 Aug 2018 12:22:41 +0000"  >&lt;p&gt;We have added&#160;&lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-2923&quot; title=&quot;Support Map&amp;lt;String, List&amp;lt;Object&amp;gt;&amp;gt; in the pojo codec&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-2923&quot;&gt;JAVA-2923&lt;/a&gt; to add support for this. In the meantime please see: &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-2920&quot; title=&quot;Add support for Map&amp;lt;String, List&amp;lt;Object&amp;gt;&amp;gt; and Map&amp;lt;String, List&amp;lt;AnotherPojo&amp;gt;&amp;gt; in PojoCodec&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-2920&quot;&gt;&lt;del&gt;JAVA-2920&lt;/del&gt;&lt;/a&gt; which has a solution.&lt;/p&gt;</comment>
                            <comment id="1977177" author="gigallo" created="Thu, 16 Aug 2018 11:22:21 +0000"  >&lt;p&gt;Hi&lt;/p&gt;

&lt;p&gt;I&apos;m using java mongodb-driver-sync version 3.8.0 but when I try to store a Map&amp;lt;String, List&amp;lt;String&amp;gt;&amp;gt; mongo returns the error:&lt;br/&gt;
&quot;a custom codec or pojocodec may need to be explicity configured and registered to handle this type&quot;&lt;/p&gt;

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

&lt;p&gt;Any help?&lt;/p&gt;

&lt;p&gt;Thanks&lt;/p&gt;</comment>
                            <comment id="1789019" author="xgen-internal-githook" created="Tue, 30 Jan 2018 15:09:01 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;email&apos;: &apos;ross.lawley@gmail.com&apos;, &apos;name&apos;: &apos;Ross Lawley&apos;, &apos;username&apos;: &apos;rozza&apos;}
&lt;p&gt;Message: Added Pojo support for Map&amp;lt;String, Object&amp;gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-2695&quot; title=&quot;Add support for Map&amp;lt;String, Object&amp;gt; in PojoCodec&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-2695&quot;&gt;&lt;del&gt;JAVA-2695&lt;/del&gt;&lt;/a&gt;&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/commit/e3c2b40cc170d3355b66eaf1c2bc3b9f078ffb50&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/e3c2b40cc170d3355b66eaf1c2bc3b9f078ffb50&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="1752850" author="aneta st&#281;pie&#324;" created="Fri, 15 Dec 2017 08:34:49 +0000"  >&lt;p&gt;Thank you! Using Document instead of Map works in version 3.6 - I&apos;m able to continue work with this workaround.&lt;br/&gt;
Having a standard Map would be a cleaner solution, so I&apos;m looking forward for this improvement. &lt;/p&gt;</comment>
                            <comment id="1747089" author="ross@10gen.com" created="Fri, 8 Dec 2017 17:58:15 +0000"  >&lt;p&gt;Currently, the PojoCodec expects every declared type to be supported by a &lt;tt&gt;Codec&lt;/tt&gt;.  I&apos;ll think on how to improve this further for your usecase.&lt;/p&gt;

&lt;p&gt;In 3.6.0 we improved the support for Maps, so to fix this you could:&lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;Add a &lt;tt&gt;Codec&amp;lt;Object&amp;gt;&lt;/tt&gt; - this is risky due the chance of recursion.&lt;/li&gt;
	&lt;li&gt;Use &lt;tt&gt;Document&lt;/tt&gt; instead of a &lt;tt&gt;Map&amp;lt;String, Object&amp;gt;&lt;/tt&gt; as there will be a codec for that and it is a &lt;tt&gt;Map&amp;lt;String, Object&amp;gt;&lt;/tt&gt;&lt;/li&gt;
	&lt;li&gt;Add a &lt;a href=&quot;http://mongodb.github.io/mongo-java-driver/3.6/javadoc/org/bson/codecs/pojo/PropertyCodecProvider.html&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;&lt;tt&gt;PropertyCodecProvider&lt;/tt&gt;&lt;/a&gt; that handles &lt;tt&gt;Map&amp;lt;String, Object&amp;gt;&lt;/tt&gt; - See the &lt;a href=&quot;http://mongodb.github.io/mongo-java-driver/3.6/bson/pojos/#generics-support&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Generics support documentation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;I hope that helps,&lt;/p&gt;

&lt;p&gt;Ross&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|htbw33:</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>