title: Map<String, HashSet<String>> to JSON, & Pretty Print
body: <p>I'm trying to make my dataset correspond to this example:</p>
  
  <pre><code>var family = [{
      "name" : "Jason",
      "age" : "24",
      "gender" : "male"
  },
  {
      "name" : "Kyle",
      "age" : "21",
      "gender" : "male"
  }];
  </code></pre>
  
  <p>I have a <code>Map&lt;String, HashSet&lt;String&gt;&gt;</code> of Names and unique alpha-numeric values correponding to specific entities to which those names could refer, let's call these entry items "IDs". </p>
  
  <p>So for instance, <code>Fyodor Mikhailovich Dostoyevsky</code> would perhaps be related to the ID <code>Q626</code>, because that's a very specific reference, there aren't many widely known figures with that name. Whereas, <code>Bush</code> might be attached to <code>G027</code>, <code>Q290</code>, and <code>Q118</code>, referencing perhaps the man, the beer, and the shrub, in no particular order. </p>
  
  <p>It looks like this (the real one is much bigger):</p>
  
  <pre><code>[Rao=[Q7293658, , Q7293657, Q12953055, Q3531237, Q4178159, Q1138810, Q579515, Q3365064, Q7293664, Q1133815], Hani Durzy=[], Louise=[, Q1660645, Q130413, Q3215140, Q152779, Q233203, Q7871343, Q232402, Q82547, Q286488, Q156723, Q3263649, Q456386, Q233192, Q14714149, Q12125864, Q57669, Q168667, Q141410, Q166028], Reyna=[Q7573462, Q2892895, Q363257, Q151944, Q3740321, Q2857439, Q1453358, Q7319529, Q733716, Q16151941, Q7159448, Q5484172, Q6074271, Q1753185, Q7319532, Q5171205, Q3183869, Q1818527, Q251862, Q3840414, Q5271282, Q5606181]]
  </code></pre>
  
  <hr>
  
  <p>Using Jackson I tried like this:</p>
  
  <pre><code>Map&lt;String, HashSet&lt;String&gt;&gt;  map = q_valMap;
  mapper.writeValue(new File("JSON_Output/user.json"), map);
  </code></pre>
  
  <p>But this seems wrong, as my output was all jumbled together, i.e.</p>
  
  <pre><code>{"Rao":["Q7293658","","Q7293657","Q12953055","Q3531237","Q4178159","Q1138810","Q579515","Q3365064","Q7293664","Q1133815"],"Hani Durzy":[""],"Louise":["","Q1660645","Q130413","Q3215140","Q152779","Q233203","Q7871343","Q232402","Q82547","Q286488","Q156723","Q3263649","Q456386","Q233192","Q14714149","Q12125864","Q57669","Q168667","Q141410","Q166028"],"Reyna":["Q7573462","Q2892895","Q363257","Q151944","Q3740321","Q2857439","Q1453358","Q7319529","Q733716","Q16151941","Q7159448","Q5484172","Q6074271","Q1753185","Q7319532","Q5171205","Q3183869","Q1818527","Q251862","Q3840414","Q5271282","Q5606181"]}
  </code></pre>
  
  <p>Do I just have to populate this JSON object iteratively?</p>
  
  <hr>
  
  <p>Like the example up top, I think it should look something like this, though what follows is only a pseudocodish characterization, which is to say, not exactly this but something similar:</p>
  
  <pre><code>{
      key: "Rao"
      value:  ["Q7293658","","Q7293657","Q12953055","Q3531237","Q4178159","Q1138810","Q579515","Q3365064","Q7293664","Q1133815"]
  
      key: "Hani Durzy"
      value: [""]
  
      key: "Louise"
      value: ["","Q1660645","Q130413","Q3215140","Q152779","Q233203","Q7871343","Q232402","Q82547","Q286488","Q156723","Q3263649","Q456386","Q233192","Q14714149","Q12125864","Q57669","Q168667","Q141410","Q166028"]
  
      key: "Reyna"
      value: ["Q7573462","Q2892895","Q363257","Q151944","Q3740321","Q2857439","Q1453358","Q7319529","Q733716","Q16151941","Q7159448","Q5484172","Q6074271","Q1753185","Q7319532","Q5171205","Q3183869","Q1818527","Q251862","Q3840414","Q5271282","Q5606181"]
  }
  </code></pre>
  
  <p>is that not right?</p>
  
  <hr>
  
  <p><strong>UPDATE</strong></p>
  
  <pre><code>public class JsonMapFileExample 
  {
      public static void map(Map&lt;String, HashSet&lt;String&gt;&gt; q_valMap ) 
      {
  
          ObjectMapper mapper = new ObjectMapper();
  
  
          ArrayNode array = mapper.createArrayNode();
          for ( Entry entry: q_valMap.entrySet() ) 
          {
            ObjectNode node = mapper.createObjectNode()
                .put("name", entry.getKey())
                .put("ids", entry.getValue());
            array.add(node);
          }
          mapper.writeValue("/home/matthias/Workbench/SUTD/nytimes_corpus/wdtk-parent/wdtk-examples/JSON_Output/user.json", array);
  
      }
  }
  
  
  class MyEntity
  {
      private String name;
      Set&lt;String&gt; value; // use names that you want in the result JSON
  
      //constructors
      public MyEntity() 
      {
  
      }
      public MyEntity(String name) 
      {
          this.name = name;
      }
  
      //getters
      public String getName() 
      {
          return this.name;
      }
      public Set&lt;String&gt;  getValue() 
      {
          return this.value;
      }
  
      //setters
      public void setName(String name) 
      {
          this.name = name;
      }
      public void setValue(Set&lt;String&gt; value) 
      {
          this.value = value;
      }
  }
  </code></pre>