I'm working on sending an array of POJOs as a response to an AJAX call.
Within my POJO, the following toString() method is defined:
@Override
public String toString() {
return "Expense [period=" + period + ", description=" + description +
", category="+ category + ", subCategory="+subCategory+", "
+ "amount="+amount+", store="+store+"]";
}
In my doGet method, I am constructing an ArrayList of these POJOs and attempting to output them using:
Gson gson = new Gson();
String json = gson.toJson(expensesForPeriod);
out.write(json);
Am I doing this correctly in terms of sending an ArrayList of JSON objects?
And on the JavaScript side, how would I convert the JSON string into an array of objects and then iterate over them?