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 am unable to add adapter annotation to a specific field (the generated proxy class must have adapter annotation). Thus, the result should be as follows :
@XmlJavaTypeAdapter(value=StringAdapter.class, type=String.class) @XmlAttribute(name = "first_name") protected String firstName;
but my binding does nothing. Just as it does not exist.
<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="xyzStringHashFunctionAdapter" name="java.lang.String" /> </bindings> </jxb:bindings>
I have no error during generation proxy class.
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: 'xyzrequest', 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?
grep
source share