why jaxb adapter annotation is not added to the proxy classes

本小妞迷上赌 提交于 2019-12-29 07:21:12

问题


My XSD looks like this:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
...
  <xs:element name="person">
    <xs:complexType>
      ...
      <xs:attribute name="first_name" use="optional" type="xs:string"/>
    </xs:complexType>
  </xs:element>
...
</xs:schema>

I can't manage to add my adapter annotation to the concrete field ( generated proxy class must have my adapter annotation). So the result should be the following:

  @XmlJavaTypeAdapter(value=StringAdapter.class, type=String.class)
    @XmlAttribute(name = "first_name")
    protected String firstName;

but my binding does not do anything. Just like it does not exists.

<jxb:bindings 
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
    xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
    version="2.1">
  <bindings schemaLocation="XMLreq.xsd" node="/xs:schema/xs:element[@name='person']/xs:complexType/xs:attribute[@name='first_name']" >
           <xjc:javaType adapter="x.y.z.StringHashFunctionAdapter" name="java.lang.String" />
  </bindings>
</jxb:bindings>

I have no error during proxy class generation.

dependencies {
    xsd2java "com.sun.xml.bind:jaxb-xjc:2.2.7"
    xsd2java "com.sun.xml.bind:jaxb-impl:2.2.7"
}
task xsd2java() {
    doLast {
        jaxbTargetDir.mkdirs()
        ant.taskdef(name: 'xjc', classname: 'com.sun.tools.xjc.XJCTask', classpath: configurations.xsd2java.asPath)
        ant.jaxbTargetDir = jaxbTargetDir
        ant.xjc(destdir: '${jaxbTargetDir}',  package: 'x.y.z.request', schema: 'src/main/resources/XMLreq.xsd', binding: 'src/main/resources/bindings.jxb')
    }
}

and my adapter.

public class StringHashFunctionAdapter extends XmlAdapter<String, String> {
    @Override
    public String marshal(String v) throws Exception { return "####hashed value####"; }

Any ideas?

来源:https://stackoverflow.com/questions/46037803/why-jaxb-adapter-annotation-is-not-added-to-the-proxy-classes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!