I'm not entirely sure how well this will work for all cases. And it only sort of works. There are errors in it, and I hadn't been too bothered to fix it.
It's a very butchered version of this post here.
Or.... well inspired from...
The requirement is some form of meta-data system or an RTTI built into your engine.
My method of serialization works like this.
Each item that can be serialized has an int that's very similar to the Radix search used in Stateless rendering.
|System|Children|Parent|Order|Type| // There is an error here... I've hadn't quite figured out Radix yet.
Naturally Type and Order can just be #Define flags.
Because these items are all looped upon in my game engine. I simply have the system wait till it's time to save before "registering"
When it's time to register. Items flagged with Serialize are copied into a buffer, and quickly ordered. Most data is saved as Entities and Components.
as it streams out bytedata, Everything is "carefully" ordered.
And... here's where things are a little wonky. I hadn't quite gotten it to the point to work fully on reload. It's capable of Loading up Entities... but components aren't loaded correctly.
Note... most of the code was written late at night and partially drunk. So all of this could just literally be unnecessary or overly complicated.
EDIT: Reading back over the code... I don't think it's worth the effort of implementing.
*nod* ...sounds like your method needs a bit more thinking; but at first glance it doesn't seem to be generalized; or allow references/cycles, or support member addition/drop-out.