JAXB is great if you have to code to some external XML spec defined as an XML schema (xsd
).
For example, you have a trading application and you must report the trades to the Uber Lame Trade Reporting App and they've given you ultra.xsd
to be getting on with. Use the $JAVA_HOME/bin/xjc
compiler to turn the XML into a bunch of Java classes (e.g. UltraTrade
).
Then you can just write a simple adapter layer to convert your trade objects to UltraTrades
and use the JAXB
to marshal the data across to Ultra-Corp. Much easier than messing about converting your trades into their XML format.
Where it all breaks down is when Ultra-Corp haven't actually obeyed their own spec, and the trade price
which they have down as a xsd:float
should actually be expressed as a double
!