Java and JSON serialization

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

luoruize
Posts: 21
Joined: 25 Aug 2009, 11:07

Java and JSON serialization

Postby luoruize » 03 Sep 2014, 19:58

Hi,
I'm trying to add a JSON serializer / deserializer to the java project, so that I will be able to better handle the data I retrieve from the server (most of it is stored in JSON format). I need something that works similarly to Newtonsoft.json in c#.
So far, I came across google's GSON. I downloaded the .jar file, added it to the project under "libs" folder, but whenever I try to use it, I'm getting the following error in the smartfox console:

java.lang.NoClassDefFoundError

I have no idea how to solve this, and couldn't find a solution online.
I'd appreciate it if anyone could either point me in the right direction, or suggest a different JSON library.

Thanks
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Java and JSON serialization

Postby Lapo » 04 Sep 2014, 10:38

The best place to put your JSON library is under SFS2X/extenions/__lib__/
This is like a "shared library" folder. In other words all Extensions will be able to use the library and it gets deployed only once.

Hope it helps

p.s. = out of the box SFS2X provides a JSON library, (net.sf.json) but I am not sure if it's fully compatible with your client C# library. In any case there's no problem using Google's implementation. Just saying :)
Lapo
--
gotoAndPlay()
...addicted to flash games
luoruize
Posts: 21
Joined: 25 Aug 2009, 11:07

Re: Java and JSON serialization

Postby luoruize » 05 Sep 2014, 14:14

Wow, thanks!!!
Only after reading your post did I recall that __lib__ library... I copied the .jar there, and everything worked well... :)
I was not aware of the JSON library provided by SFS, and it doesn't have to be compatible with my C# code, since I'm only using it to read data from the DB. If it can serialize and deserialize JSONs to and from custom classes, then it might work for me, as well...
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Java and JSON serialization

Postby Lapo » 05 Sep 2014, 15:43

I think it does, you can give it a try. In any case both solutions are good.
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 121 guests