Skip to content

Commit 7114c02

Browse files
authored
Merge pull request #1054 from poorva1209/update_timeseries_response
updated timeseries response format
2 parents 27a766a + 89e8d31 commit 7114c02

File tree

1 file changed

+5
-23
lines changed

1 file changed

+5
-23
lines changed

gov.pnnl.goss.gridappsd/src/gov/pnnl/goss/gridappsd/dto/TimeSeriesEntryResult.java

+5-23
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
public class TimeSeriesEntryResult {
1414
ArrayList<HashMap<String,Object>> data;
15+
1516

1617
public ArrayList<HashMap<String,Object>> getData() {
1718
if(data==null){
@@ -32,33 +33,14 @@ public String toString() {
3233
}
3334

3435
public static TimeSeriesEntryResult parse(String jsonString) {
36+
Type listType = new TypeToken<ArrayList<HashMap<String, Object>>>(){}.getType();
3537
Gson gson = new Gson();
36-
TimeSeriesEntryResult obj = gson.fromJson(jsonString, TimeSeriesEntryResult.class);
38+
TimeSeriesEntryResult obj = new TimeSeriesEntryResult();
39+
ArrayList<HashMap<String, Object>> data = gson.fromJson(jsonString, listType);
40+
obj.setData(data);
3741
if(obj.data==null)
3842
throw new JsonSyntaxException("Expected attribute measurements not found");
3943
return obj;
40-
}
41-
42-
public static void main(String[] args){
43-
44-
Type listType = new TypeToken<ArrayList<HashMap<String, Object>>>(){}.getType();
45-
46-
String jsonString = "{\"data\":[{\"Diffuse\":19.958636,\"AvgWindSpeed\":7.9434,\"TowerRH\":31.61,\"long\":\"105.18 W\",\"MST\":\"13:44\",\"TowerDryBulbTemp\":74.534,\"DATE\":\"892013\",\"DirectCH1\":-0.0531206845,\"GlobalCM22\":20.2478337,\"AvgWindDirection\":359.3,\"time\":1376077440,\"place\":\"Solar Radiation Research Laboratory\",\"lat\":\"39.74 N\"}]}";
47-
Gson gson = new Gson();
48-
//jsonString = jsonString.substring(8, jsonString.length()-1);
49-
50-
System.out.println(jsonString);
51-
52-
//ArrayList<HashMap<String, Object>> obj = gson.fromJson(jsonString, listType);
53-
TimeSeriesEntryResult obj = gson.fromJson(jsonString, TimeSeriesEntryResult.class);
54-
System.out.println(obj);
55-
56-
57-
58-
59-
60-
61-
6244
}
6345

6446
}

0 commit comments

Comments
 (0)