Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tell jaxb to not remove underscores


Is there a way to tell JAXB to not remove underscores when creating getter/setter names from XML Schema?
Reason: this causes loss of information and it is harder to trip between XML and Java; e.g. in written communications where one participant might be confused about "different names".

Example: NR_ROR should not become getNRROR but getNR_ROR.
Note: I believe that the less-mangled names are worth the "violation" of Java naming convention.
TIA
karolrvn

like image 590
KarolDepka Avatar asked Jan 29 '10 17:01

KarolDepka


1 Answers

Create a custom binding and set "underscoreBinding" to "asCharInWord". One approach is to create a file called binding.xjb and use the -b flag to tell xjc where it is. Here's an example of what you'd put in binding.xml:

<jaxb:bindings
   xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
   version="1.0">
   <jaxb:bindings schemaLocation="foobar.xsd">
      <jaxb:globalBindings underscoreBinding="asCharInWord"/>
   </jaxb:bindings>
</jaxb:bindings>
like image 178
lreeder Avatar answered Oct 21 '22 23:10

lreeder