code: public JSONObject serialize(Map<String, Object> out) {
          JSONObject json = new JSONObject();
          json.put("device_id", deviceId);
          json.put("project_id", projectId);
          out.put("device_id", deviceId);
          out.put("project_id", projectId);
          JSONArray sourcesArr = new JSONArray();
          List<String> sourceNames = new ArrayList<String>(store.keySet());
          Collections.sort(sourceNames);
          for (String k : sourceNames) {
              JSONObject temp = new JSONObject();
              temp.put("name", k);
              JSONArray dataArr = new JSONArray();
              for (DataPoint d : store.get(k)) {
                  dataArr.put(d.toJson());
              }
              temp.put("data", dataArr);
              sourcesArr.put(temp);
          }
          json.put("sources", sourcesArr);
          out.put("sources", sourcesArr);
          return json;
      }
docs: Custom serialization method for this object to JSON.
  
  @param out In-out parameter that maps JSON keys to their values.
  @return A JSONObject representing this object.