Problem with SFSObject.newFromJsonData

Post here your questions about the Java client / Android API for SFS2X

Moderators: Lapo, Bax

SergeyR
Posts: 4
Joined: 12 Jan 2018, 11:24

Problem with SFSObject.newFromJsonData

Postby SergeyR » 15 Aug 2018, 09:49

Hello,

I'm using Java API to write web application which will receive json data throught some REST methods and then will make appropriate ExtensionRequest to our SmartFox server. Based on java-doc there is a newFromJsonData method in SFSObject class, however I've got an error when I try to use it. Java API is 1.7.3.

Code: Select all

java.lang.ClassNotFoundException: com.smartfoxserver.v2.entities.data.SFSObjectLite
   at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
   at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
   at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:565)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
   at com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.decodeSFSObject(DefaultSFSDataSerializer.java:288)
   at com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.json2object(DefaultSFSDataSerializer.java:281)
   at com.smartfoxserver.v2.entities.data.SFSObject.newFromJsonData(SFSObject.java:188)
User avatar
Lapo
Site Admin
Posts: 20915
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Problem with SFSObject.newFromJsonData

Postby Lapo » 15 Aug 2018, 11:33

Hi,
sorry, JSON is not included/supported in the client side API.
The method exists because the client uses the same SFSObject library that the server uses but it's never used on client side, therefore dependencies are not bundled.

If you need to work with JSON data you can add a JSON library to your project such as this:
https://github.com/stleary/JSON-java

Hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games
SergeyR
Posts: 4
Joined: 12 Jan 2018, 11:24

Re: Problem with SFSObject.newFromJsonData

Postby SergeyR » 15 Aug 2018, 12:05

I do not think that this will solve my problem. I have an JSON object and I need to convert it to SFSObject so it can be passed to SmartFox server. There is no need to process JSON at all, just to convert it to the structure that can be used by SmartFox server.

Besides that, that is kind of weird that there is a method in interface which in fact does not exist in library.
User avatar
Lapo
Site Admin
Posts: 20915
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Problem with SFSObject.newFromJsonData

Postby Lapo » 15 Aug 2018, 16:24

As I mentioned, the method exists only because we're reusing the same SFSObject library from the SFS2X server side.
In SFS2X there used to be a JSON-SFS2X direct conversion when websocket support was initially introduced and text-based protocol was employed.
JSON however has been put to rest quite a while ago (3 years ago, I think) because everything uses binary serialization, instead of text which is less efficient.

With that out of the way I think in theory it should be possible to have JSON<->SFS2X conversion if you import all the necessary libraries from the SFS2X side.
The library used in SFS2X is "JSON-lib"
http://json-lib.sourceforge.net/

which in turn depends on several other Apache commons libs, all of which are found under SFS2X/lib.
You can add them to your project and you should be able to use the conversion. (Can't guarantee 100% because I have never tried this myself).

Hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games
SergeyR
Posts: 4
Joined: 12 Jan 2018, 11:24

Re: Problem with SFSObject.newFromJsonData

Postby SergeyR » 15 Aug 2018, 17:33

Thank you, I will check this library.

Return to “SFS2X Java / Android API”

Who is online

Users browsing this forum: No registered users and 2 guests