@SuppressWarnings("unchecked")
  private JSONObject extractCounters(Counters counters) {
    JSONObject counterArray = new JSONObject();
    for (CounterGroup group : counters) {
      JSONObject counterGroup = new JSONObject();

      for (Counter counter : group) {
        counterGroup.put(counter.getName(), counter.getValue());
      }
      counterArray.put(group.getName(), counterGroup);
    }
    return counterArray;
  }
  @SuppressWarnings("unchecked")
  public Counters restoreCounters(JSONObject object) {
    Set<Map.Entry<String, JSONObject>> groupSet = object.entrySet();
    Counters counters = new Counters();

    for (Map.Entry<String, JSONObject> groupEntry : groupSet) {
      CounterGroup group = new CounterGroup(groupEntry.getKey());
      Set<Map.Entry<String, Long>> counterSet = groupEntry.getValue().entrySet();
      for (Map.Entry<String, Long> counterEntry : counterSet) {
        Counter counter = new Counter(counterEntry.getKey(), counterEntry.getValue());
        group.addCounter(counter);
      }
      counters.addCounterGroup(group);
    }
    return counters;
  }