开发者

how use xmlAdapter in maven-jaxb-plugin

Hi I have xsd schema with base64Binary. when this plugin genereted this elemen looks like

@XmlElement(name = "element")
    protected byte[] element;

but how can I tell to this plugin to use @XmlJavaTypeAdapter(HexBinaryAdapter.class) so I need something like this

@XmlJavaTypeAdapter(HexBinaryAdapter.class)
    @XmlElement(name 开发者_StackOverflow中文版= "element")
    protected byte[] element;

I hope that this is possible thx for help

PS: I cant modify classes which were generated by these plugin because they are always rewrited


You should create a JAXB schema bindings file that instructs the JAXB implementation to use the built in javax.xml.bind.DatatypeConverter to perform conversions to/from hexBinary.

<jxb:bindings 
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
    version="2.1">
    <jxb:bindings schemaLocation="YourSchema.xsd">
        <jxb:bindings node="//xs:element[@name='element']">
            <jxb:property>
                <jxb:baseType>
                    <jxb:javaType name="byte[]"
                        parseMethod="javax.xml.bind.DatatypeConverter.parseHexBinary" 
                        printMethod="javax.xml.bind.DatatypeConverter.printHexBinary"/>
                </jxb:baseType>
            </jxb:property>
        </jxb:bindings>
    </jxb:bindings>
</jxb:bindings>

For More Information

  • http://blog.bdoughan.com/2011/08/xml-schema-to-java-generating.html
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜