为什么 JAXB 2 RI 的 XJC 简单模式会更改集合名称?
JAXB简单绑定模式将集合名称修改为其复数 “版本”,例如“additionalData”变为“additionalDatas”。有什么解决方案可以改变这种行为吗?我需要一个与 XSD 字段名称相同的 Java 字段名称和方法名称。我的绑定文件:
<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xsi:schemaLocation="
http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
version="2.1">
<globalBindings>
<serializable uid="1" />
<xjc:simple/>
</globalBindings>
</bindings>
JAXB simple binding mode modifies collection names to their plural
'version', e.g. "additionalData" becomes "additionalDatas". Is there any solution to change this behavior? I need to have a Java field name and methods name equal to XSD field name. My bindings file:
<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xsi:schemaLocation="
http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
version="2.1">
<globalBindings>
<serializable uid="1" />
<xjc:simple/>
</globalBindings>
</bindings>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
“简单绑定模式”是JAXB RI (Metro)的扩展功能。将集合属性名称设为复数是其设计的一部分。
来自: http://weblogs.java.net/blog/ kohsuke/archive/2007/01/using_jaxb_ris.html
您可以使用正常的架构自定义来控制属性名称。请参阅我之前的答案之一(下面的链接):
The "simple binding mode" is an extended feature of the JAXB RI (Metro). Making the collection property names plural was part of its design.
From: http://weblogs.java.net/blog/kohsuke/archive/2007/01/using_jaxb_ris.html
You may be able to use the normal schema customizations to control the property name. Refer to one of my previous answers (link below):
以下是一个利用 JAXB2 Simplify 插件 其中可以禁用复数化。
Here is an example plugin configuration that leverages the JAXB2 Simplify Plugin which among other things can disable pluralization.