4

Given the below structure/ background, can someone briefly outline (at a high level) a good structure to follow- coding with JAXB when xsd can be modified after compilation?

Background information:

My project currently uses JAXB (and aspectj?) to generate classes at compilation time from xsd initiated in build.xml file. These classes then extend a single parent class.

At runtime, we unmarshall generated xml strings (using xsd classes and objectFactory) and cast to the parent object. Basically following similar to the oracle documentation I found here: https://docs.oracle.com/cd/E19575-01/819-3669/6n5sg7bj5/index.html

Problem is the xsd can now change at runtime. This would likely imply we can no longer use auto generated classes. So what would be a good strategy to update for this change in specs?

JavaBeast
  • 766
  • 3
  • 11
  • 28
  • *"what would be a good strategy?"* Stop using JAXB, since JAXB is for static (compile-time) XML schemas. If the XML schema can change at runtime, you can't write Java code to use the JAXB objects anyway (unless you use reflection), so what is the point of making them classes? Sounds like the system needs to be redesigned. – Andreas May 31 '17 at 01:59
  • @Andreas Yeah i figured it would need a faily large redesign. I must have missed jaxb being static. I would be looking for an answer (in similar fashion to my "background" section) outlining an alternative design to JAXB then – JavaBeast May 31 '17 at 02:07
  • maybe something like this? https://stackoverflow.com/questions/15732/whats-the-best-way-to-validate-an-xml-file-against-an-xsd-file – JavaBeast May 31 '17 at 02:22
  • That just validates the XML. It doesn't make the data in the XML available to use in Java code. – Andreas May 31 '17 at 02:23
  • Im seeing alot of eclipselink Dynamic JAXB/MOXy stuff out there. Maybe this would help me? http://www.eclipse.org/eclipselink/documentation/2.5/solutions/jpatoxml006.htm – JavaBeast Jun 01 '17 at 02:58
  • "Using dynamic JAXB we will bootstrap our JAXBContext on the XML schema itself. If the XML schema were to change, we would not need to regenerate any classes." – JavaBeast Jun 01 '17 at 03:10

0 Answers0