Val, I think Ignite Serialization should follow the approach similar to what Java serialization does: it can transparently and consistently handle both Serializable and Externalizable classes. It can do it because it relies on a single class - ObjectOutputStream - to do serialization (and a single class - ObjectInputStream - to do the opposite, but let's ignore it for the moment). ObjectOutputStream delegates to proper user callbacks (writeObject or writeExternal) at the right moments, but otherwise it fully controls the on-the-wire representation and takes care of all the necessary stream framing/marking so that ObjectInputStream can then correctly deserialize the bytes. It's never a problem for Java to serialize an Externalizable field from a Serializable object and vice versa. Users can mix and match serialization APIs as they please.
I think Ignite should just have a single marshaller, let's say the Binary, which drives the whole serialization process. It doesn't delegate to OptimizedMarshaller as it does today. Instead it detects the Serializable/Externalizable classes and calls their serialization callbacks - writeObject/writeExternal - passing in *itself* as ObjectOutputStream/ObjectOutput correspondingly. This way the entire serialization process never leaves the context of a single Binary marshaller and allows Ignite to handle such complex cases as the one we're discussing now. I hope it makes sense. Andrey > From: [email protected] > Date: Fri, 19 Feb 2016 19:15:07 -0800 > Subject: Binary object inside Externalizable > To: [email protected] > > Folks, > > I recently faced an issue which seems to be pretty critical. As you know, > when binary marshaller meets an Externalizable object, it switches to > optimized marshaller. And if there is a regular object inside, it's still > serialized with optimized, even if its type is declared in binary > configuration with custom mapper, etc. This looks wrong. > > It's getting even worse in compute grid, because closure processor wraps > user's closures in some internal classes, which are Externalizable, so > these closures are always serialized with optimized marshaller. > > Does anyone have ideas on what is the proper fix for this? > > -Val
