JAXB 简单绑定(bind)模式将集合名称修改为其复数形式 “版本”,例如“附加数据”变为“附加数据”。有什么解决方案可以改变这种行为吗?我需要一个 Java 字段名和方法名等于 XSD 字段名。我的绑定(bind)文件:
<?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>
最佳答案
“简单绑定(bind)模式”是 JAXB RI (Metro) 的一个扩展特性。使集合属性名称复数是其设计的一部分。
发件人:http://weblogs.java.net/blog/kohsuke/archive/2007/01/using_jaxb_ris.html
My favorite feature in the JAXB RI is the simpler and better binding mode, which makes the generated code even easier to use, by ...
- Eliminating JAXBElement as much as possible
- Giving you a better, more typed binding in general
- Use plural property names where applicable
您可以使用正常的模式自定义来控制属性名称。引用我之前的一个回答(链接如下):
关于java - 为什么 JAXB 2 注册机的 XJC 简单模式会更改集合名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5155560/