getUtfStringArray returns an error

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

Moderators: Lapo, Bax

User avatar
marsoups
Posts: 164
Joined: 14 Apr 2008, 03:30

getUtfStringArray returns an error

Postby marsoups » 24 Aug 2019, 02:24

I think I have found a bug with the getUtfStringArray server code (Java).

Here is how to reproduce.

Code: Select all

String[] STRING_ARRAY= new String[]{"test 1","test 2","test 3"};
ISFSObject testObj = new SFSObject();
testObj.putUtfStringArray("push", Arrays.asList(STRING_ARRAY));
System.out.println("This looks fine : " + testObj.toJson());
System.out.println("Print the array : " + testObj.getUtfStringArray("push"));



This results in the following error:

12:32:23,377 ERROR [SFSWorker:Ext:3] v290.ExtensionReqController - java.lang.ClassCastException:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: java.lang.ClassCastException
Message: java.util.Arrays$ArrayList cannot be cast to com.smartfoxserver.v2.entities.data.ISFSArray
Description: Error while handling client request in extension: { Ext: example, Type: JAVA, Lev: ZONE, { Zone: example}, {} }
Extension Cmd: call
+--- --- ---+
Stack Trace:
+--- --- ---+
com.smartfoxserver.v2.entities.data.SFSObject.getSFSArray(SFSObject.java:461)
com.smartfoxserver.v2.entities.data.SFSObjectLite.getUtfStringArray(SFSObjectLite.java:162)
User avatar
Lapo
Site Admin
Posts: 21276
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: getUtfStringArray returns an error

Postby Lapo » 24 Aug 2019, 10:18

Hi,
it sounds like you might be running an old version of the server. What version is it?

Thanks
p.s. = I tested under 2.13 and it works just fine.
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
marsoups
Posts: 164
Joined: 14 Apr 2008, 03:30

Re: getUtfStringArray returns an error

Postby marsoups » 26 Aug 2019, 03:26

Hi, my version is 2.13.0

I have looked into this and found that you are indeed correct, and the example I provided is not sufficient to reproduce my error. I spent time trying to produce it as the actual code we have is more complicated, and finally managed to narrow it down to this :

Code: Select all

   String[] STRING_ARRAY= new String[]{"test 1","test 2","test 3"};
      ISFSObject testObj = SFSObject.newFromJsonData("{\"another_array\": [1]}");
      testObj.putUtfStringArray("push", Arrays.asList(STRING_ARRAY));
      System.out.println("Print the array : " + testObj.getUtfStringArray("push"));


Will result in:
12:32:23,377 ERROR [SFSWorker:Ext:3] v290.ExtensionReqController - java.lang.ClassCastException:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: java.lang.ClassCastException
Message: java.util.Arrays$ArrayList cannot be cast to com.smartfoxserver.v2.entities.data.ISFSArray


What I think may be happening here, is that newFromJsonData forms a sort of ISFSArray rather than an ISFSObject ?
User avatar
Lapo
Site Admin
Posts: 21276
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: getUtfStringArray returns an error

Postby Lapo » 26 Aug 2019, 07:24

Yes,
because typed arrays don't exist in JSON/Javascript when you create a typed array you're actually just creating an SFSArray which is an array-like data structure that can accept all supported types.

NOTE: JSON support has been introduced a long time ago mainly to support the text-based websocket protocol, which is now surpassed and no longer used (replaced by binary websocket). Generally speaking I would not recommend serializing via JSON and instead using the binary encoding, which is more efficient and type safe.

Binary encoding is obtained via the SFSObject.toBinary() and SFSObject.newFromBinaryData() methods.

Hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 8 guests