public JSONObject toJson() { JSONObject JSONObjectShoppingList = new JSONObject(); JSONArray JSONArrayListEntry = new JSONArray(); JSONArray JSONArrayUser = new JSONArray(); try { JSONObjectShoppingList.put("id", id).put("name", name).put("status", status); for (ListEntry le : this.listEntry) { JSONArrayListEntry.put(le.toJson()); } for (AppUser user : this.userList) { JSONArrayUser.put(user.toJson()); } JSONObjectShoppingList.put("listEntry", JSONArrayListEntry); JSONObjectShoppingList.put("user", JSONArrayUser); } catch (JSONException ex) { Logger.getLogger(ShoppingList.class.getName()).log(Level.SEVERE, null, ex); } return JSONObjectShoppingList; }