title: Send huge json object from Java Servlet
body: <p>Java servlet returns JSON object.</p>
  
  <pre><code>response.setContentType("application/json");
  response.getWriter().write(json.toString()); 
  </code></pre>
  
  <p>JSON object contains data fetched from table (database) size of which > 50 MB.</p>
  
  <p>On running, servlet throws this error:</p>
  
  <pre><code>java.lang.OutOfMemoryError: Java heap space
  </code></pre>
  
  <p>It seems the issue is while writing json data. Server is unable to allocate contiguous memory of size> 50 MB to the String.</p>
  
  <p>I am unable to figure out fix for this issue. How can I send huge JSON object from Servlet? </p>