BinaryExporter stored class name / BinaryImporter object creation

BinaryExporter uses the line

BinaryClassObject bco = classes.get(object.getClass().getName());


to get the class of an object. In jME Physics 2 the physics implementation decides which concrete type of objects are created. The type that should be stored is the interface not the concrete class name. There would be several ways to solve this:

  • add a method to Savable to determine the class name (this requires all implementors to be changed) and call


BinaryClassObject bco = classes.get(object.getWrittenClassName());



  • add another interface with the getWrittenClassName() method that can be optionally implemented (would add an instanceof check)

  • store the classname like any other field


I would favour the second one.

The same problem when restoring: Objects are created by

Savable out = (Savable)Class.forName(bco.className).newInstance();


Which does not work when there is no parameterless constructor and/or a factory is used. Which is the case in jME Physics 2, too. As there already is a lookup of the BinaryClassObject I would suggest to store a strategy/factory instead of (or in addition to) the className. This wouldn't cost performance (maybe even gain as the class lookup would be only once).

Any comments / objections?

Isn't this exactly what we are talking about in the convertors thread?

I'm currently working on this (see the Converter thread: http://www.jmonkeyengine.com/jmeforum/index.php?topic=3303.0).

whoops - didn't read all thread yet, sorry - will do now