Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
279 views
in Technique[技术] by (71.8m points)

java - why jaxb adapter annotation is not added to the proxy classes

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...