title: Multimap to JSON
body: <p>I have a very huge Multimap. I an trying to convert this Multimap to JSONArray as a key value. But i am getting the following Error:</p>
  
  <pre><code>Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
  at java.util.Arrays.copyOf(Arrays.java:2367)
  at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:130)
  at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:114)
  at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:415)
  at java.lang.StringBuffer.append(StringBuffer.java:237)
  at java.io.StringWriter.write(StringWriter.java:112)
  at com.google.gson.stream.JsonWriter.string(JsonWriter.java:544)
  at com.google.gson.stream.JsonWriter.value(JsonWriter.java:404)
  at com.google.gson.internal.bind.TypeAdapters$13.write(TypeAdapters.java:353)
  at com.google.gson.internal.bind.TypeAdapters$13.write(TypeAdapters.java:337)
  at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
  at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.write(MapTypeAdapterFactory.java:209)
  at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.write(MapTypeAdapterFactory.java:146)
  at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
  at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:89)
  at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:195)
  at com.google.gson.internal.bind.ObjectTypeAdapter.write(ObjectTypeAdapter.java:105)
  at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
  at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:96)
  at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:60)
  at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
  at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:89)
  at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:195)
  at com.google.gson.internal.bind.ObjectTypeAdapter.write(ObjectTypeAdapter.java:105)
  at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
  at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:96)
  at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:60)
  at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
  at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.write(MapTypeAdapterFactory.java:209)
  at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.write(MapTypeAdapterFactory.java:146)
  at com.google.gson.Gson.toJson(Gson.java:586)
  at com.google.gson.Gson.toJson(Gson.java:565)
  </code></pre>
  
  <p>I have tried :</p>
  
  <pre><code>Multimap&lt;String,JSONArray &gt; multiMap = ArrayListMultimap.create();
  String jsonString = gson.toJson(multiMap.asMap());
  </code></pre>
  
  <p>While searching for the issue i came to know about the concept of Streaming and trid to appy it. by following:</p>
  
  <p><a href="https://sites.google.com/site/gson/streaming" rel="nofollow noreferrer">https://sites.google.com/site/gson/streaming</a></p>
  
  <p>But that example shows a List but not a Multimap as a keyvalue pair. Can anyone please suggest how can i convert this multimap to a JSONArray.</p>
  
  <p>Note: I have tried to increase the heap in eclipse to 2048 but still i have the same issue.</p>
  
  <p>I am still facing the same issue. Can anyone please suggest? :(</p>