JAXB绑定用于使用CXF进行代码生成

huangapple go评论76阅读模式
英文:

JAXB Bindings for code generation using CXF

问题

我正在使用CXF代码生成插件和jaxb从WSDL生成Java存根。在绑定中,我已经指定了一个特定对象,在其中一个存根中,必须是一个String对象,即使XSD将其指定为整数。

绑定:

    <jxb:bindings schemaLocation="../../../../../WSDL_Package/ABC/ABC_1.xsd">
            <jxb:bindings node="//xs:complexType[@name='TypeI']//xs:sequence//xs:element[@name='number']">
                <xjc:javaType name="java.lang.String" adapter="javax.xml.bind.annotation.adapters.XmlAdapter" />
            </jxb:bindings>
        </jxb:bindings>

但是在项目中使用这些存根时,我收到异常消息:

> 信息: 无法创建类javax.xml.bind.annotation.adapters.XmlAdapter的新实例
> java.lang.InstantiationException

有人能帮助解决这个问题吗?
英文:

I am generating Java stubs from a WSDL using CXF codegen plugin and jaxb. In the bindings, I have specified that one particular object in one of the stubs has to be a String object even though the XSD has specified it as an integer.

The binding:

&lt;jxb:bindings schemaLocation=&quot;../../../../../WSDL_Package/ABC/ABC_1.xsd&quot;&gt;
        &lt;jxb:bindings node=&quot;//xs:complexType[@name=&#39;TypeI&#39;]//xs:sequence//xs:element[@name=&#39;number&#39;]&quot;&gt;
            &lt;xjc:javaType name=&quot;java.lang.String&quot; adapter=&quot;javax.xml.bind.annotation.adapters.XmlAdapter&quot; /&gt;
        &lt;/jxb:bindings&gt;
    &lt;/jxb:bindings&gt;

But on using the stubs in my project, I get the exception

> INFO: failed to create a new instance of class
> javax.xml.bind.annotation.adapters.XmlAdapter
> java.lang.InstantiationException

Can someone help with resolving this issue?

答案1

得分: 1

因为 javax.xml.bind.annotation.adapters.XmlAdapter 是一个抽象类,无法被实例化。您必须实现您的适配器。

public final class MyAdapter extends XmlAdapter<Type1,Type2> { ... }
英文:

Because javax.xml.bind.annotation.adapters.XmlAdapter is an abstract class and cannot be instantiated. You must implement your adapter.

public final class MyAdapter extends XmlAdapter&lt;Type1,Type2&gt; { ... }

huangapple
  • 本文由 发表于 2020年4月7日 13:24:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/61073318.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定