title: How to serialize a Map of a Map with GSON?
body: <p>I want to serialize my Example class below into JSON using GSON.</p>
  
  <pre><code>import com.google.gson.Gson;
  import com.google.gson.GsonBuilder;
  import java.util.LinkedHashMap;
  
  public class Example
  {
      private LinkedHashMap&lt;String,Object&gt; General;
  
      private static final String VERSION="Version";
      private static final String RANGE="Range";
      private static final String START_TIME="Start_Time";
      private static final String END_TIME="End_Time";
  
      public Example() {
          General = new LinkedHashMap&lt;String,Object&gt;();
          General.put(VERSION, "0.1");
  
          LinkedHashMap&lt;String,String&gt; Range = new LinkedHashMap&lt;String, String&gt;();
          Range.put(START_TIME, "now");
          Range.put(END_TIME, "never");
  
          General.put(RANGE, Range);
      }
  
      public String toJSON() {
          Gson gson = new GsonBuilder().serializeNulls().create();
          return gson.toJson(this);
      }
  }
  </code></pre>
  
  <p>I expected to get the following output:</p>
  
  <pre><code>{"General":{"Version":"0.1","Range":{"Start_Time":"now","End_Time":"never"}}}
  </code></pre>
  
  <p>But calling the function <code>toJSON()</code> returns</p>
  
  <pre><code>{"General":{"Version":"0.1","Range":{}}}
  </code></pre>
  
  <p>It seems that GSON cannot serialize the Map <code>Range</code> inside the Map <code>General</code>. Is this a limitation of GSON or am I doing something wrong here?</p>