Skip to content

Instantly share code, notes, and snippets.

@Heroes84
Last active July 8, 2016 09:24
Show Gist options
  • Save Heroes84/c06d40c73cc19077beaf29eb81d5ed5d to your computer and use it in GitHub Desktop.
Save Heroes84/c06d40c73cc19077beaf29eb81d5ed5d to your computer and use it in GitHub Desktop.
GSON TypeToken
/get json array from json string
JsonArray jarray = jobject.getAsJsonArray("reportRecords");
//get a list of reportRecords using Gson
Gson mGson = new Gson();
Type listType = new TypeToken<List<DataMetrics>>(){}.getType();
List<DataMetrics> dataMetricsList = mGson.fromJson(reportRecordsJsonArray, listType);
//Filter only the ones with a specific name
List<DataMetrics> dataMetricsFilteredList = dataMetricsList.stream().filter(dataMetric -> dateMetric.getName.equals("Client::Sync"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment