Page 1 of 1

Disconnection on calling toJson() for SFSObject

Posted: 06 Dec 2012, 14:12
by suvroz
I am trying to call toJson() on SFSObject in the dispatch method of my class (which implements IEventListener):

Code: Select all

@Override
public void dispatch(BaseEvent event) throws SFSException {
    if (event.getType().equalsIgnoreCase(SFSEvent.EXTENSION_RESPONSE))
    {
        ISFSObject params = (ISFSObject) eventArgs.get("params");
        if (params.getUtfString("Request").equalsIgnoreCase("GAME_START_COUNTDOWN_END"))
        {
            Log.e("control reaches here");         
            String jsonParam = params.toJson();
            //TODO do something
        }
    }
}


The log saying "control reaches here" gets printed when I get a message from the server. However if I have the "toJson" call, the client gets disconnected with the following warning/error messages:

12-06 19:03:33.362: W/System.err(16362): 39774 [Thread-15] INFO sfs2x.client.core.EventDispatcher - Dispatching event OnDisconnect to 1 listeners
12-06 19:03:33.362: W/System.err(16362): 39781 [Thread-15] ERROR sfs2x.client.core.sockets.TCPSocketLayer - TCPSocketLayer: Socket error: net.sf.json.JSONObject
12-06 19:03:33.362: W/System.err(16362): 39782 [Thread-15] INFO sfs2x.client.core.EventDispatcher - Dispatching event OnError to 1 listeners
12-06 19:03:33.362: W/System.err(16362): 39782 [Thread-15] INFO sfs2x.client.core.EventDispatcher - Dispatching event disconnect to 1 listeners
12-06 19:03:33.372: W/System.err(16362): 39783 [Thread-15] INFO sfs2x.client.core.EventDispatcher - Dispatching event connectionLost to 1 listeners


if I remove the "toJson" line, there is no disconnection. Has anyone faced similar problems? Can anyone please help understand and fix this issue?

We are using Server version 2.4.0 and Client API version 1.0.5 (both latest available for download as of now).

Re: Disconnection on calling toJson() for SFSObject

Posted: 10 Dec 2012, 14:34
by Lapo
Thanks for reporting we will take a look as soon as possible

Re: Disconnection on calling toJson() for SFSObject

Posted: 12 Dec 2012, 10:01
by Lapo
UPDATE:
the problem is that the JSON conversion is not implemented/supported in the client API.
The toJSON() method is a legacy coming from the Server side version of the SFSObject but it's never used on the client side, so we didn't include the JSON library which would only make the API heavier.

We recommend using the binary codec by calling toBinary() and newFromBinary() methods

thanks