users@jaxb.java.net

How to use subclasses of JAXB created classes

From: William Saxton <saxton_at_gmail.com>
Date: Thu, 14 Jun 2007 10:13:15 -0400

Hey all,

  I have a bunch of JAXB created classes, FooData, BarData, etc. Using the
"Strategy pattern" I want each class to have a method, pair(), that will
return a list of key/value pairs.

  My first thought was to create classes, such as SuperFooData,
SuperBarData, etc, which extended FooData, BarData and implemented
Pairable. The problem with this approach, is that it is fairly difficult to
marshall data from XML into a subclass.

  My second thought was to have SuperFooData have an instance variable
"FooData" and implement Pairable. The problem with this approach is that I
would have to go back through all of my code and change all instance
variables of type "FooData" to "superFooData.getFooData()".

  Another thought would be to simply add this method to the JAXB generated
classes, but it would make changing the class's schema almost impossible,
given that you'd have to regenerate the classes and paste back in your
'pair()' method code. Heck, I don't even know if you can unmarshall data
into a modified class...

  Has anyone attempted to subclass a JAXB class? If so, what approaches
have you used to make this as painless as possible?

-Bill