Serialization and filesystem

Hello,



I started implementing Serializable objects for the server part of my project. Everything worked fine, I was able to load and save objects to the filesystem… until I wanted to serialize a Vector. I started investigating and noticed they don’t use Java’s Serialization system, but something internal to SpiderMonkey.



I have a few questions about this :

  • Why aren’t Vectors, and other objects, Serializable ?
  • Should I implement SpiderMonkey (the Network interfaces) instead of Java’s Serialization ?
  • If yes, how ? I don’t find any precise documentation in the wiki.
  • Can SpiderMonkey Serialize data to the filesystem, using a stream ?



    I’m a bit confused because Java had a very simple to use system .



    Thanks for your help.

Vectors don’t have the serializable annotation but instead they have a dedicated Serializer class that is able to write them more efficiently.

I seen this, but all this is in the network packages…

Serialization is not only for networking, and in my case I wish to use it to load and save data to the filesystem.



Should I implement SpiderMonkey to save my objects.? Or is it dedicated to network only.



I’m trying to figure out how to implement it.

The only doc I find is deprecated ( https://wiki.jmonkeyengine.org/legacy/doku.php/spidermonkey:tutorial:serializing )

I seen there’s a topic about Serialization in the Documentation for Advanced Users.

But it’s not linked. Is it in project ? Not at all in project ? Lacking documentation ? :slight_smile:

You are mixing up spidermonkeys serialization for network and the savable serialization system for the scenegraph and objects therein.



You can save any savable like this (if its a spatial you save, the result would be a j3o file):

BinaryExporter.getInstance().save(savable, file);



Then you can load the asset, given a BinaryLoader is registered for the extension:

Spatial asset = AssetManager.loadAsset(“My/Asset.xxx”);

Thank you normen,

I will take a look at BinaryExporter. Since it eats a stream, I will maybe be able to merge it with my own save system.



Sorry for mixing things up. I’m still learning how to use jMonkey. :slight_smile:

Just two questions for personal curiosity.

Why don’t you use Java’s integrated Serialization systems ? And why is there one for the network and one for exports ?

Its different requirements, on the one side you want to be able to store and recreate a complete scene and link it to existing data, on the other side you want to transfer self-contained bits of data between scenes. Since the process of loading and saving a scene involves pretty specific requirements “faking” general compatibility of some kind and working around implementation details of an existing serialization system would really not be a benefit, rather the opposite.