Page 1 of 1

Can't send HashMap<String, Integer> to the client...

Posted: 12 Sep 2010, 13:23
by altefquatre
Hi,

I'm currently doing a Java extension, and I'd like to send a HashMap<String, Integer>, but on client side, I only receive a null object.
The message type is XTMSG_TYPE_XML.

Server side code:

Code: Select all

ActionscriptObject response = new ActionscriptObject();
LinkedList ll = new LinkedList();
HashMap<String, Integer> map;

ll.add(user.getChannel());

map = new HashMap<String, Integer>();
map.put("10", 1);
map.put("20", 2);
map.put("30", 3);

response.put("_cmd", s);
response.putMap("constants", map);

this.sendResponse(response, fromRoom, null, ll);
Client side code:

Code: Select all

var resObj : Object = e.params.dataObj;
			
if (resObj._cmd != "getMoveInterpreterConstants" ||
    e.params.type != SmartFoxClient.XTMSG_TYPE_XML)
{
	throw new Error("[MoveInterpreter] Unhandled response (" + resObj._cmd + ", " + e.params.type + ")");
}

// resObj.constants is null.			
this.fieldA = resObj.constants["10"];
this.fieldB = resObj.constants["20"];
this.fieldC = resObj.constants["30"];
It works fine when I'm sending a HashMap<String, String>. Is there some restrictions on putMap? I looked in the doc but couldn't find any details about that... Or XML messages with HashMap can only handle <String, String>?...

Thanks for your help.

Posted: 12 Sep 2010, 19:26
by BigFIsh
You will need to convert your hashmap data into JSONObject or ActionscriptObject before sending it to the client - as the server and client message parser cannot parse hashmap (in other words, it is not supported).

Posted: 13 Sep 2010, 01:53
by altefquatre
Ok thanks for the answer!