users@jaxb.java.net

Re: How to use subclasses of JAXB created classes

From: William Saxton <saxton_at_gmail.com>
Date: Fri, 22 Jun 2007 14:03:19 -0400

Hi Christophe,

  That actually looks very much like what I'm trying to do. I'm on
vacation right now, but I'll be sure to check this out when I get back
next week!

  Thanks.

-Bill

On 6/21/07, Christophe Alexandre <alexandre_at_magillem.com> wrote:
> 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
>