Not answer
Be careful about disabling serialization for selected classes. You may not need to βclusterβ the application and not use replicated messages or state objects if they run locally or in some limited development environment. However, after deployment for testing or production, it can be grouped. Then it will break if you prevent serialization.
Therefore, the best reason is to ensure the "serializability" of your classes, and not to prevent it.
Serialization Off answer
If you insist on disabling serialization, removing <distributable/> from your web.xml should do the trick.
Serializing Non-Serializable Responses
Having tried several serializable classes, you will find that the types of certain members of the class are simply not serializable, and you cannot change the type to something like that that will be serialized. Then use the following trick, if applicable:
public class ClassForcedToBeSerializable implements Serializable { transient private FileWriter writer;
As you can see, the class includes a field of type FileWriter . We ensured serialization of the object -> bytes, by marking it transient . However, on the remote JVM, when this class returns from bytes, the field of the FileWriter field will be null . We avoid this problem by recreating it during deserialization (see the readObject() method).
This example only works because the File field contains sufficient state for FileWriter to successfully recreate.
diginoise
source share