JAXB和complexType共享名称与其中一个元素生成不正确的代码 [英] JAXB and complexType sharing name with one of it's elements generates incorrect code

查看:242
本文介绍了JAXB和complexType共享名称与其中一个元素生成不正确的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个xsd有点不好,但我必须使用它来避免改变我正在写的servlet的接口。请求 - 响应接口的xsd包含以下行:

I have this xsd which is kind of bad, but I have to use it to avoid changing the interface of the servlet I’m writing. The xsd for the request-response interface contains the following lines:

<xs:complexType name="Foo">
    <xs:sequence minOccurs="0" maxOccurs="unbounded">
        <xs:element name="Foo">
        ...
        </xs:element>
    ...
    </xs:sequence>
<xs:complexType>

注意名称冲突。当我使用maven-jaxb-plugin从这个模式生成类时,我最终得到:

Notice the name clash. When I use the maven-jaxb-plugin to generate classes from this schema I end up with:

Public class Foo {
...

   public List<Foo.Foo> getFoo() {
   ...
   }

   ...

   public static class Foo {
   ...
   }
}

当然,这不能编译,因为它不允许使用嵌套类和封闭类上的相同名称。如果不更改xsd,我该怎么做才能解决这个问题?我知道你可以通过在xsd中添加jaxb的标签来覆盖名称。这样做安全吗?它会对服务的接口产生影响吗?

This fails to compile, of course, since it’s not permitted to use the same name on the nested class and the enclosing class. What can I do to solve this, without changing the xsd? I know you can override name by adding tags for jaxb in the xsd. Is it safe to do that? Will it have an impact on the interface of the service?

推荐答案

您可以使用外部绑定文件来自定义生成的类名。有关示例,请参阅:

You can use an external binding file to customize the generated class names. For an example see:

  • JAXB: How to change XJC-generated classes names when attr type is specified in XSD?

这篇关于JAXB和complexType共享名称与其中一个元素生成不正确的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆