Implementing serializable

I wrote my own networking piece which does serialization based on api that comes with java already. import java.io.Serializable;.

Just implementing this interface allows for that object to be serialized (with some exceptions, like it can’t be a thread). I wanted to know if there was a way I could get core classes such as spatial or ColorRGBM to implement serializable without taking the following approaches.


  1. I could just open the class from the source and implement it myself, but then if I get a new build I would have to redo it for all source code I changed. Plus I shouldn’t be changing the source.


  2. I could make a new class and extend the classes I want to serialize. Such as class MyColorRGBM extends ColorRGBM implements Serialzable. But again that would leave me with a lot of extra overhead.



    I just wanted to know if there was another way that makes this process easier, maybe I’ll have to write code to automate the process, but how do I do that?



    The other possibility is to have JME by default implementing serializable in the future to allow support for alternate networking pieces.



    Just a thought. Any help is much appreciated.

You can use Serializer.registerSerializer(ColorRGBM.class, [YourColorRGBSerializer]), right or am I misunderstanding you?

I’m not using Spidermonkey, I already wrote my own networking layer in which it uses the default serialization method. Meaning just implement the class you want serialized with serializable.



lets say I have my message classes which sends messages



[java]public class Message implements Serializable

{

String hey;

int hey;

}[/java]



this will go through fine because by default objects are already serializable.



if I wanted to do



[java]public class Message implements Serializable

{

String hey;

int hey;

ColorRGBA mycolor;

}[/java]



I will get an exception because ColorRGBA doesnt implement Serializable. I am asking how can I go about making classes in jmonkey use the java.io.Serializable without having to do the things I have listed.



Thanks

This is more of a general Java question than a jME question; nonetheless - You’d have to wrap it in another object like you first showed - some overhead is involved there, or you change Java source :stuck_out_tongue:



So option 2 :slight_smile:

I can only tell you nto to sue the default serilisation as it is slow as hell, and produces large bloat binary. Not pseakring for spidermonkey, but my own network layer I use uses a 2 byte identifyer and after that the direct bynary values (so if a send a mesage containg a vector3f and a quaternion I send 2+43+44 = 30 bytes) The default serializer was around 100-200 for the same payload.

EmpirePhoenix said:
I can only tell you nto to sue the default serilisation as it is slow as hell, and produces large bloat binary. Not pseakring for spidermonkey, but my own network layer I use uses a 2 byte identifyer and after that the direct bynary values (so if a send a mesage containg a vector3f and a quaternion I send 2+4*3+4*4 = 30 bytes) The default serializer was around 100-200 for the same payload.

Yep, and that is the exact reason why SpiderMonkey doesn't use Java Serializable. SpiderMonkey uses a short identifier as well.

… I can also tell that I really shouldn’t post in the forum when drunk(birthday)

yeah when I was doing my networking piece I read that java by default wasn’t the best with performance, but I also read that I have the option of overriding their send and write methods whenever I wanted to put a better performance piece in. I guess the good news about that is I get to still keep the same structure and can just “plug in” and upgrade.

that’s right!

EmpirePhoenix said:
.. I can also tell that I really shouldn't post in the forum when drunk(birthday)

Happy Birthday :)