• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can Data Binding with Jaxb do this?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm been using Jaxb to write XML files. For each class created by Jaxb (e.g. X.java), I wrote my own derivative class (e.g. Y.java) with additional data and methods, since I needed richer classes with more than the skeleton setters and getters and referenced data that Jaxb provides. So, when I build the set of objects, I construct my class (Y) rather than the original Jaxb created X class, and the XML file is created correctly. So far so good.
Now I want to go the other way and read XML files, and have Jaxb construct the objects of *my* derived classes, rather than the skeleton Jaxb generated classes. But, I don't see a way to do that. In other words, for XML element X, I want:
At build time:
- Jaxb writes class X.java
- I provide class Y.java, which is derived from X.java
At run time:
- Jaxb reads XML file
- For each X Element, Jaxb instantiates my derived Y class (not the X class).
I don't think Jaxb's ability to take a user-provided class name solves the problem. That just makes Jaxb generate the source under a different class name, but still doesn't instantiate my class.
Is there a way to do what I want, or am I asking too much? Seems to me like this would be a common need.
Thanks,
Ron
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd like to be able to do this, too!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic