title: Gson make firebase-like json from objects
body: <p>In the past a manually created as list of data, which was stored locally in a database. Now I would like to parse those data and put them through <strong>import json</strong> option into firebase dbs, but what I get doesn't look like firebase generated json.</p>
  
  <p>What I get is:</p>
  
  <pre><code>[  
     {  
        "id":"id_1",
        "text":"some text"
      },
      {  
        "id":"id_2",
        "text":"some text2"
      },
      ...
  ]
  </code></pre>
  
  <p>what I want is something like this:</p>
  
  <pre><code>{  
     "id_1": {  
        "text":"some text",
        "id":"id_1"
      },
      "id_2":{  
        "text":"some text2",
        "id":"id_1"
      },
      ...
  }
  </code></pre>
  
  <p>my Card class</p>
  
  <pre><code>class Card{
      private String id;
      private String text;
  
  }
  </code></pre>
  
  <p>retrieving data </p>
  
  <pre><code>//return list of card
  List&lt;Card&gt; cards =myDatabase.retrieveData();
  Gson gson = new Gson();
  String data = gson.toJson(cards);
  </code></pre>
  
  <p>So how I can I achieve this (it looks to me) dynamically named properties for json that look like those generated by firebase ? </p>
  
  <p><strong>EDIT:</strong>
  I found that gson has FieldNamingStrategy interface that can change names of fields. But it looks to me it's not dynamic as I want. </p>
  
  <p><strong>EDIT2</strong>
  my temp fix was to just override toString()</p>
  
  <pre><code> @Override
   public String toString() {
       return "\""+id+"\": {" +
                       "\"text\":" + "\""+text+"\","+
                       "\"id\":" +"\""+ id +"\","+
                       "\"type\":"+ "\""+ type +"\""+
               '}';
      }
  </code></pre>