Is it supposed to work? I have the doubts that I can't serialize to the client a Map Object, am I correct? How can we know the limits of the serialization? Do we must be sure that AS can recnognize the objects we want to use?
Thank you for your help.
I would simply suggest to print the content of the jso with jso.toString() or similar. It should have a method that dumps() the actual json data. This way you can double check if it's legal.
If at runtime it doesn't fire any errors I think it should work.
And it should result in an object inside another object, from an AS3 perspective
while the java hash is in practice an associative array, what about the Map?
I am not getting the question.
In java a Map represents a key-value pair based collection... there are many names for this same thing in other languages: associative array, dictionary etc...
HashTable, HashMap, ConcurrentHashMap etc... are all the same type of key-value pair based collections with slightly different characteristics.
The "hash" thing simply describes a technique (called "hashing") for speeding up the research of items in the Map
Did you succeed serializing the ConcurrentHashMap<String, Map<String, Object>> ?
Does it work?
I don't know Java, but if it works like the C++ stl a map can't be translated in an AS Object, at most it can be a Dictionary.
Anyway this is what one of my colleague reported:
after a deep examination I found that there is a problem in the json.jar package bundled with SmartFoxServer;
this library is loaded by the server but it's a old (maybe bugged software) version that lacks some functionality;
this package doesn't conform to the JSON RFC 4627 in the fact that isn't able to serialize very complex structured data;
the RFC 4627 requires that all objects keys must be double quoted ( mainly key => string values ) but the current library stops at the first level of a structure without descending deeply;
I suppose that a wrong formatted json object is the cause of client flash API decoding errors;
After some test, I've compiled the most recent ( latest version is @version 2008-09-18 ) json java source and I've built a new package that I've updated on Rome and Singapore servers;
the old extension response was:
{"userList":"{01-3389={host=01, name=mirmor, rooms=[2568]}, 02-3514={host=02, name=kikkosa, rooms=[2860]}}"}
and the new extension response is:
{"userList":{"01-3389":{"host":"01","name":"mirmor","rooms":[2568]},"02-3514":{"host":"02","name":"kikkosa","rooms":[2860]}}}
but the situation seems more complex and problematic and I've rollbacked all:
SFS logs give errors on it.gotoandplay.smartfoxserver.SmartFoxServer.dispatchEvent method line 1190: java.lang.NoSuchMethodError.
it.gotoandplay.smartfoxserver.SmartFoxServer not only uses the old library but calls a JSONObject method, "getData()",
( it should be: HashMap jso = (new JSONObject(msg)).getData();) that doesn't exist anymore in the latest library (not library upgrading is probably due to that) and the source code and the api doc confirm my sad discovery.
SFS json.jar package CAN'T be used for complex structured data exchange.
Anyway, beside the things reported, I still can't understand how complex objects can be mapped into AS object.
I'm intereted to understand.
About the long post of your colleague:
1. could you specify which languge is used on the server side? Java? Actionscript?
2.
Anyway, beside the things reported, I still can't understand how complex objects can be mapped into AS object.
I'm intereted to understand.
I don't know exactly what are you referring to when you say "complex object"
You can't map a Java class to an Actionscript class for obvious reasons. But you can send structured data from Java using Maps and Lists and obtain an equivalent structure in Actionscript that uses Objects and Arrays.
So in other words: Java Map ==> JSON ==> Actionscript Object Java List ==> JSON ==> Actionscript Array
By mixing/nesting Maps & Lists (java) or Objects & Arrays (AS) you can exchange quite complicated game data.
It was not clear who was doing what So I guess you posted the code instead of your colleague and then reported what he said ... whatever
In Java we have updated the JSON support since 1.5.9 or so with an alternative library that should conform the standards.
Here's the library --> http://json-lib.sourceforge.net/
The AbstractExtension class that you extend exposes the following JSON related methods:
public void sendResponse(net.sf.json.JSONObject jso, int fromRoom, User sender, LinkedList recipients)
The 2nd version takes ad the JSON object argument from the new library, so you can use that instead which should help you with the proper serialization.
Generic Exception: java.lang.NoSuchMethodError: org.json.JSONObject.getData()Ljava/util/HashMap;
java.lang.NoSuchMethodError: org.json.JSONObject.getData()Ljava/util/HashMap;
at it.gotoandplay.smartfoxserver.SmartFoxServer.dispatchEvent(SmartFoxServer.java:1150)
at it.gotoandplay.smartfoxserver.SmartFoxServer.readIncomingMessages(SmartFoxServer.java:1027)
at it.gotoandplay.smartfoxserver.EventReader.run(EventReader.java:32)
at java.lang.Thread.run(Unknown Source)
and not on send message from server, but on receive it from client. We could not use net.sf.json.JSONObject in this case tom improve situation.
The debug flag of the SmartFoxClient class, when turned on it will log debugging information in the Flash IDE console or Flex console.
The json expression you specified in the post is valid and correct, and I am able to parse it with the org.json.JSONObject class used in SmartFoxServer.
I think I would need to see both the code sending the data and the relative client debug informations.