users@jaxb.java.net

Re: How to use subclasses of JAXB created classes

From: Christophe Alexandre <alexandre_at_magillem.com>
Date: Thu, 21 Jun 2007 19:35:38 +0200

Hi,
I'm new on the list and maybe I don't understand your problem but
isn't this:
https://jaxb.dev.java.net/guide/Adding_behaviors.html
an answer to your problem ?

Regards.
Christophe.

Le 21 juin 07 à 10:11, Aleksei Valikov a écrit :

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