<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:52:53 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-709] com.mongodb.util.JSON should provide JSON#serialize( Object o, Writer writer) and JSON#serialize( Object o, OutputStream out) to have a better support for streaming</title>
                <link>https://jira.mongodb.org/browse/JAVA-709</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;To serialize a BasicDBObject to a JSON content, it uses the &lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/blob/master/src/main/com/mongodb/util/JSON.java&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/blob/master/src/main/com/mongodb/util/JSON.java&lt;/a&gt; which provides the JSON#serialize( Object o, StringBuilder buf).&lt;/p&gt;

&lt;p&gt;IMHO, I think it should be better to provides 2 methods with Writer and OutputStream: &lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;JSON#serialize( Object o, Writer writer)&lt;/li&gt;
	&lt;li&gt;JSON#serialize( Object o, OutputStream out)&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Why? Because if you wish returns the JSON content from a Servlet (HttpServletResponse#getWriter(), HttpServletResponse#getOutputStream()), we cannot use streaming mode. We need to create a StringBuilder and put it to the http response writer or outpustream :&lt;/p&gt;

&lt;p&gt;-------------------------------------------------------&lt;br/&gt;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {&lt;br/&gt;
  BasicDBObject  o = ...;  &lt;br/&gt;
  StringBuilder buf = new StringBuilder ();&lt;br/&gt;
  JSON.serialize(o, buf);&lt;br/&gt;
  response.getWriter().write(buf.toString());&lt;br/&gt;
  // same code :&lt;br/&gt;
  //response.getWriter().write(o.toString());&lt;br/&gt;
}&lt;br/&gt;
-------------------------------------------------------&lt;/p&gt;

&lt;p&gt;I think it should be better to do with streaming mode like this:&lt;/p&gt;

&lt;p&gt;-------------------------------------------------------&lt;br/&gt;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {&lt;br/&gt;
  BasicDBObject  o = ...;  &lt;br/&gt;
  JSON.serialize(o, response.getWriter());&lt;br/&gt;
}&lt;br/&gt;
-------------------------------------------------------&lt;/p&gt;</description>
                <environment></environment>
        <key id="58733">JAVA-709</key>
            <summary>com.mongodb.util.JSON should provide JSON#serialize( Object o, Writer writer) and JSON#serialize( Object o, OutputStream out) to have a better support for streaming</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</type>
                                            <priority id="4" iconUrl="https://jira.mongodb.org/images/icons/priorities/minor.svg">Minor - P4</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="2">Won&apos;t Fix</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="angelozerr">Angelo</reporter>
                        <labels>
                            <label>driver</label>
                    </labels>
                <created>Sat, 8 Dec 2012 16:16:29 +0000</created>
                <updated>Wed, 31 Jan 2018 19:51:56 +0000</updated>
                            <resolved>Wed, 31 Jan 2018 19:51:56 +0000</resolved>
                                                                    <component>API</component>
                                        <votes>2</votes>
                                    <watches>1</watches>
                                                                                                                <comments>
                            <comment id="1791034" author="jeff.yemin" created="Wed, 31 Jan 2018 19:51:56 +0000"  >&lt;p&gt;The &lt;tt&gt;com.mongodb.util.JSON&lt;/tt&gt; class is deprecated, so we won&apos;t be expanding its API.  Please note that the &lt;tt&gt;JsonWriter class&lt;/tt&gt; which has replaced it does take a &lt;tt&gt;Writer&lt;/tt&gt;.&lt;/p&gt;</comment>
                            <comment id="217184" author="angelozerr" created="Mon, 17 Dec 2012 13:39:37 +0000"  >&lt;p&gt;By waiting for your decision, I have created mongo-jee project and I have putted my code on Git at &lt;a href=&quot;https://github.com/angelozerr/mongo-jee/tree/master/src/main/java/com/mongodb/jee/util&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/angelozerr/mongo-jee/tree/master/src/main/java/com/mongodb/jee/util&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="217060" author="angelozerr" created="Mon, 17 Dec 2012 10:20:54 +0000"  >&lt;p&gt;I have modified source of 2.10.1 to manage streaming with JSON.serialize which provides 2 methods : &lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;JSON#serialize( Object o, Writer writer)&lt;/li&gt;
	&lt;li&gt;JSON#serialize( Object o, OutputStream out)&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Note that I have changed the package to com.mongodb.jee.util to have none conflict with my JEE support for MongoDB and your driver.&lt;/p&gt;

&lt;p&gt;I&apos;m using this JSON serialize methods with Servlet (Writer) and JAX-RS MessageBodyWriter.&lt;/p&gt;</comment>
                            <comment id="215757" author="angelozerr" created="Sat, 15 Dec 2012 11:40:40 +0000"  >&lt;p&gt;It seems this issue is similat than &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-104&quot; class=&quot;external-link&quot; rel=&quot;nofollow&quot;&gt;https://jira.mongodb.org/browse/JAVA-104&lt;/a&gt;&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                            <attachment id="22571" name="AbstractObjectSerializer.java" size="1474" author="angelozerr" created="Mon, 17 Dec 2012 10:20:54 +0000"/>
                            <attachment id="22572" name="ClassMapBasedObjectSerializer.java" size="3109" author="angelozerr" created="Mon, 17 Dec 2012 10:20:54 +0000"/>
                            <attachment id="22573" name="JSON.java" size="16061" author="angelozerr" created="Mon, 17 Dec 2012 10:20:54 +0000"/>
                            <attachment id="22574" name="JSONCallback.java" size="5255" author="angelozerr" created="Mon, 17 Dec 2012 10:20:54 +0000"/>
                            <attachment id="22575" name="JSONSerializers.java" size="16826" author="angelozerr" created="Mon, 17 Dec 2012 10:20:54 +0000"/>
                            <attachment id="22570" name="ObjectSerializer.java" size="1523" author="angelozerr" created="Mon, 17 Dec 2012 10:20:54 +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|hrkz7b:</customfieldvalue>

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