java - How to disable Wildfly 9.0.2 trying to serialize certain classes in a clustered application -
during set of cluster i'm having issue wildfly/infinispan attempting serialize number of classes fine recreated on each instance - although whatever reason seem determined distribute across cluster.
initially thought @stateless annotation have effect wanted, although throws issue not having correct constructors, don't believe looking for.
what proper way disable this, or overwrite method of serialization, on per-class basis?
the non-answer
be careful approach of disabling serialisation selected classes. application might not need 'clustered' , not needing replicated sesssions or stateful entities, when run locally or in limited development environment. once deployed test or production clustered. it's going broken, if have prevented serialization.
therefore best cause of action ensure 'serializability' of classes, rather force-preventing it.
serialization off answer
if insist on disabling serialization, removing <distributable/>
web.xml
should trick.
serializing non-serializables answer
by trying make classes serializable find types of class members non-serializable , cannot swap type similar, serialize. use following trick, providing applicable:
public class classforcedtobeserializable implements serializable { transient private filewriter writer; //filewriter not serializable!!! private final file file; public classforcedtobeserializable(file file) throws ioexception { this.file = file; this.writer = new filewriter(file); } //flesh , bones here private void readobject(java.io.objectinputstream in) throws ioexception, classnotfoundexception { in.defaultreadobject(); if (writer == null) { this.writer = new filewriter(file); } } }
as can see class includes field of filewriter
type. ensured object -> bytes serialization marking transient
. on remote jvm when class being brought bytes, filewriter
field field null
. avoid problem recreating during deserialization (see readobject()
method).
this example works because file
field carries enough state filewriter
recreated.
Comments
Post a Comment