If you want the Java class to be Serializable, you need to recursively add Serializable to all existing fields. Is there any IDE functionality or tool to do this automatically?
java
It's not a direct answer, but I thought it might be misunderstood, so I'll write it down.
All existing fields must be recursively serializable
is sufficient, but not necessary.
For example, if you have a Parent
with the following Child
type in the field,
class Parent implements Serializable {
private child;
// ...
}
US>class Child {
}
Child
type is not Serializable
, so the Parent
is actually non-serial, not .
If the child
field contains the following types of instances, it can be serialized:
class SerializableChild extensions Child implements Serializable {
}
Alternatively, child
can be serialized even if null
.
On the other hand, serialization fails if the following types of instances are set:
class NonSerializableChild extensions Child {
}
(Executable sample code: http://ideone.com/2ER9Dm)
Javadoc calls it
Class serialization is enabled by the class that implements the java.io.Serializable interface.In classes that do not implement this interface, the state is not serialized or restored in series.
(omitted)
You might encounter objects that do not support serializable interfaces while patrolling graphs.In this case, a NotSerializableException is thrown, and this exception identifies the class of non-serial objects.
Translating to make it easier to understand
serializable
or ignored during serialization or de-serialization (see Javadoc's subsequent text for details)Serializable
or an exception is thrown at runtimeThat's what it means.
You do not need to declare Serializable in the fields of the class implemented (implementations).
In other words, the fields of a class implemented with Serializable must be primitive or serializable.
Are you looking for Edia who can:
public class Sample implementable{
public Child;
}
After creating this Sample class, if you try to create a Child class,
public class Child [implementations Serializable This Is Automatically Created] {
}
Is that so?
It doesn't seem to be there, so I tried to make something easy by myself.
For now, I only need to serialize all classes under a folder, but sometimes a slightly complicated class doesn't work.
https://github.com/lamrongol/MakeJavaClassSerializable
© 2024 OneMinuteCode. All rights reserved.