XMLEncoder and inheritance problem

D

dpdoughe

I'd like to use XMLEncoder on classes that do not strictly adhere to
the JAVA Beans spec. I do this by writing PersistenceDelegate and
BeanInfo files. This part works on specific classes. I'd like to
define an abstract class with a method writeItXML that writes the
class itself into XML.

1) I have an abstract class named AbstractFoo
2) AbstractFoo has a method defined writeItXML() which calls an
XMLEncoder's writeObject on the "this" object.
3) I have also written AbstractFooBeanInfo and
AbstractFooPersistenceDelegate
4) I extend AbstractFoo and create ParticularFoo. I create
ParticularFooBeanInfo and ParticularFooPersistenceDelegate but do not
override the writeItXML class method defined in AbstractFoo.

5) When an instance of ParticularFoo calls writeItXML() the
AbstractFooBeanInfo is read and XMLEncoder throws an
InstantiationException.

writeObject seems to always reflect to the most encumpasing super
class rather than the current class (further down in the inheritance
hierarchy). The main error seems to be that it reads in the wrong
BeanInfo class -> AbstractFooBeanInfo instead of ParticularBeanInfo.
Perhaps writeObject should start at the bottom of the inheritance
stack?

The only workaround I can see right now is to override writeItXML in
every extension class of AbstractFoo as well as BeanInfo and
PersistenceDelegate classes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top