java 为什么 JAXB 2 RI 的 XJC 简单模式会更改集合名称?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5155560/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why does JAXB 2 RI's XJC simple mode change collection names?
提问by User123456789
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:
JAXB 简单绑定模式将集合名称修改为其复数“版本”,例如“additionalData”变为“additionalDatas”。有什么解决方案可以改变这种行为吗?我需要一个 Java 字段名称和方法名称等于 XSD 字段名称。我的绑定文件:
<?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>
回答by bdoughan
The "simple binding mode" is an extended feature of the JAXB RI (Metro). Making the collection property names plural was part of its design.
“简单绑定模式”是 JAXB RI(Metro)的扩展特性。使集合属性名称复数是其设计的一部分。
From: http://weblogs.java.net/blog/kohsuke/archive/2007/01/using_jaxb_ris.html
来自: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
JAXB RI 中我最喜欢的功能是更简单和更好的绑定模式,它使生成的代码更易于使用,通过...
- 尽可能消除 JAXBElement
- 为您提供更好、更类型化的绑定
- 在适用的情况下使用复数属性名称
You may be able to use the normal schema customizations to control the property name. Refer to one of my previous answers (link below):
您或许能够使用正常的架构自定义来控制属性名称。请参阅我之前的答案之一(以下链接):