I have a couple of 3D objects that are added to a TransformGroup
. The 3D objects do not exist as variables, but are added to the TransformGroup
via new Sphere()
for example, however the TransformGroup
class does not implement Serializable
interface.
So, how should I be able to serialize my objects to a file and have acces to my objects when reading the file?
P.S. I don't really know how to serialize to XML file, and I am not sure if that would be a good option for what I need.
Not only the TransformGroup
, but your individual primitives like Sphere
as well, all lack the Serializable
interface. So although you could obtain the list of all children quite easily, serializing that list isn't a big step forward. The objects look like Java Beans, at least at first glance. If they actually are, then you could use a XMLEncoder
to serialize them. Notice that the XML generated this way might contain pretty much arbitrary Java commands, so deserializing such a file from an untrusted source might be a security hazard. I guess there are third party Bean encoders out there which avoid that problem. But the XMLEncoder
might be a reasonable first step to see whether this works at all, or if not, where it fails.