使用 MOXy 生成具有默认 minOccurs 的模式
我尝试使用 EclipseLink MOXy 2.1.2 和 Java 1.6 基于我的域类生成架构,遵循以下示例: http://wiki.eclipse.org/EclipseLink/Examples/MOXy/JAXB/GenerateSchema
但是,默认的 minOccurs 值存在问题。如果注释 @XmlElement 未指定必需的属性,则它应默认为 false,这意味着生成模式时 minOccurs 应为 0。这与 Sun 的 JAXB 实现的预期一致。但是,使用 Moxy 时,不会生成 minOccurs,并且隐含默认值 1。
例如,
public Integer getDuration() {
return duration;
}
应该生成
<xs:element name="duration" type="xsd:int" minOccurs="0"/>
相反,如果使用 Moxy,它会生成
<xsd:element name="duration" type="xsd:int"/>
这意味着 minOccurs="1",因为这是默认值。这是一个错误吗?有什么解决方法吗?
提前致谢!
I'm trying to use EclipseLink MOXy 2.1.2 and Java 1.6 to generate a schema based on my domain classes, following this example: http://wiki.eclipse.org/EclipseLink/Examples/MOXy/JAXB/GenerateSchema
However there is an issue with the default minOccurs value. If the annotation @XmlElement does not specify the required attribute, it should default to false, which means when generating the schema minOccurs should be 0. This works as expected with Sun's JAXB implementation. However when using Moxy minOccurs is not being generated and the default value of 1 is implied.
For example,
public Integer getDuration() {
return duration;
}
Should have generated
<xs:element name="duration" type="xsd:int" minOccurs="0"/>
Instead if using Moxy it generates
<xsd:element name="duration" type="xsd:int"/>
which means minOccurs="1" since that is the default. Is this a bug? Is there any workaround for this?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
感谢您的回复,布莱斯。问题似乎是由于我试图通过指定 propOrder = {} 来生成 xsd:all 。使用该注释,MOXy 不会生成 minOccurs="0"。我修改了您的演示类来演示该问题:
以下内容是使用 MOXy 生成的。请注意,没有 minOccurs 属性:
如果删除 @XmlType(propOrder = {}) 注释,则生成的模式会存在 minOccurs,但元素作为序列:
仅供参考,下面是 Sun 的 JAXB 参考实现生成的内容:
提前致谢!
Thanks for your response, Blaise. The problem seems to be due to the fact that I'm trying to generate xsd:all by specifying propOrder = {}. With that annotation MOXy doesn't generate the minOccurs="0". I've modified your demo class to demonstrate the issue:
The following is produced with MOXy. Notice there is no minOccurs attribute:
If you remove the @XmlType(propOrder = {}) annotation the generated schema has the minOccurs present but with the elements as a sequence:
And just for reference, here is what is generated by Sun's JAXB reference implementation:
Thanks in advance!
您是否有可能使用 EclipseLink 2.1.2 的预发行版本? EclipseLink 2.1.2 的发布版本可以在这里获取:
当我运行以下示例时:
我得到:
UPDATE #1
基于您的 更新,这是一个问题。我打开了以下 EclipseLink MOXy bug:
更新 #2
我们已在 EclipseLink 2.2 流中解决了此错误。该修复程序可从 12 月 21 日开始的夜间下载中获取:
此修复最终也将包含在 2.1.3 补丁中。
Is there any chance you are on a pre-release version of EclipseLink 2.1.2? The released version of EclipseLink 2.1.2 can be obtained here:
When I run the following example:
I get:
UPDATE #1
Based on your update, this is an issue. I have opened the following EclipseLink MOXy bug:
UPDATE #2
We have addressed this bug in the EclipseLink 2.2 stream. The fix can be obtained from the nightly downloads starting December 21st:
This fix will also eventually be included in the 2.1.3 patch.