I want to send back a Map> in a response from a servlet:
Map<UserAccount,ArrayList<CardSet>> sharedsets = DataDAO.getPublicSets();
String responseMessage = gson.toJson(sharedsets,Map.class);
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.setStatus(HttpServletResponse.SC_ACCEPTED);
response.getWriter().write(responseMessage);
response.getWriter().flush();
... I recieve this in javascript:
$.get("/lod1/Scuttlebutt",{name:"onload",data: -1},function(jsondata){
console.log(jsondata);
});
.. it seems that the list is getting correctly converted but not the key. What should I do so that I can access the attributes of the key too ? And how would I do that in Javascript? This is the output I seee in the console:
Object
flashcardshark.bean.UserAccount@54
Array(16)
0
{Name: "a", setID: 1, description: "empty", status: "Shared"}
1
{Name: "d", setID: 2, description: "d", status: "Shared"}
2
{Name: "d", setID: 3, description: "d", status: "Shared"}
3
{Name: "d", setID: 4, description: "d", status: "Shared"}
4
{Name: "d", setID: 5, description: "ds", status: "Shared"}
5
{Name: "d", setID: 6, description: "dsadf", status: "Shared"}
6
{Name: "d", setID: 37, description: "d", status: "Shared"}
7
{Name: "a", setID: 59, description: "a", status: "Shared"}
8
{Name: "d", setID: 89, description: "d", status: "Shared"}
9
{Name: "d", setID: 90, description: "d", status: "Shared"}
10
{Name: "d", setID: 91, description: "dd", status: "Shared"}
11
{Name: "d", setID: 97, description: "d", status: "Shared"}
12
{Name: "d", setID: 100, description: "d", status: "Shared"}
13
{Name: "a", setID: 101, description: "a", status: "Shared"}
14
{Name: "d", setID: 102, description: "d", status: "Shared"}
15
{Name: "a", setID: 103, description: "a", status: "Shared"}
... So everything about this is ok flashcardshark.bean.UserAccount@54