告诉jaxb不要删除下划线 [英] tell jaxb to not remove underscores
问题描述
是否可以通过XML Schema创建getter/setter名称时告诉JAXB不要删除下划线?
原因:这会导致信息丢失,并且更难在XML和Java之间切换;例如在书面交流中,一位参与者可能对不同的名字"感到困惑.
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".
示例:NR_ROR不应成为getNRROR,而应成为getNR_ROR.
注意:我相信,较少混用的名称值得Java命名约定的违反".
TIA
karolrvn
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
推荐答案
创建自定义绑定,并将"underscoreBinding"设置为"asCharInWord".一种方法是创建一个名为binding.xjb的文件,并使用-b标志告诉xjc它在哪里.这是您放入binding.xml中的示例:
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>
这篇关于告诉jaxb不要删除下划线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!