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

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

Post Reply
altefquatre
Posts: 2
Joined: 12 Sep 2010, 12:58

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

Post 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.
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Post 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).
Smartfox's forum is my daily newspaper.
altefquatre
Posts: 2
Joined: 12 Sep 2010, 12:58

Post by altefquatre »

Ok thanks for the answer!
Post Reply