I am trying to send an array of pojo's as a response to an ajax call.
Inside of my pojo, I have the following toString():
@Override
public String toString() {
return "Expense [period=" + period + ", description=" + description +
", category="+ category + ", subCategory="+subCategory+", "
+ "amount="+amount+", store="+store+"]";
}
Then, inside of my doGet method, I build up the arraylist of pojos, and am trying to write them out, using:
Gson gson = new Gson();
String json = gson.toJson(expensesForPeriod);
out.write(json);
Where expensesForPeriod is an arraylist of expense objects.
Is this the correct way to send an arraylist of json objects?
On the javascript side, how would I convert the json string to an array of objects, and iterate over them?