Originariamente inviato da andreaben94
Come faccio a salvare un oggetto che contine oggetti non serializabili
Se dovessi guardare solo a questa domanda, la risposta è non si può. Semplicemente perchè così è scritto nella documentazione di Serializable

Classes that do not implement this interface will not have any of their state serialized or deserialized
Ma c'è anche scritto quanto segue:

To allow subtypes of non-serializable classes to be serialized, the subtype may assume responsibility for saving and restoring the state of the supertype's public, protected, and (if accessible) package fields. The subtype may assume this responsibility only if the class it extends has an accessible no-arg constructor to initialize the class's state. It is an error to declare a class Serializable if this is not the case. The error will be detected at runtime.
Questo significa che se vuoi serializzare un oggetto "non serializable", dovrai essere tu a prenderti carico di serializzare tutti i suoi campi pubblici, protected e "package" (senza modificatore)... e la cosa poi è possibile solo se poi si è in grado di ricostruire effettivamente l'oggetto.


Ciao.