Say jaxb not to remove underscores


Is there a way to tell JAXB not to remove underscores when creating getter / setter names from an XML schema?
Reason: this leads to loss of information, and it is more difficult to travel between XML and Java; for example, in written communications where one participant may be confused about "different names."

Example: NR_ROR should not become getNRROR, but getNR_ROR.
Note. I believe less distorted names deserve a β€œviolation” of the Java naming convention.
TIA
karolrvn

+4
source share
3 answers

Create a custom binding and set the "underscoreBinding" parameter to "asCharInWord". One approach is to create a file called binding.xjb and use the -b flag to tell xjc where it is. Here is an example of what you set 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> 
+15
source

Take a look at the underscore that jaxb provides. See, for example, in the docs here β†’ http://java.sun.com/webservices/docs/1.5/tutorial/doc/JAXBUsing4.html

I have never used it since I like camelCaseWords, but it looks like it does what you are looking for.

+1
source

I came here to see how to do the same, with the additional qualifications that the circuit is built into WSDL. To do this, combine fooobar.com/questions/1161124 / ... with the leader's answer above by changing:

 schemaLocation="foobar.xsd" 

to

 wsdlLocation="foobar.wsdl" 

Net result:

 <jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0"> <jaxb:bindings wsdlLocation="foobar.wsdl"> <jaxb:globalBindings underscoreBinding="asCharInWord"/> </jaxb:bindings> </jaxb:bindings> 

This is at least using the JAXWS Reference Implementation.

+1
source

Source: https://habr.com/ru/post/1299757/


All Articles