質問

I am using xjc(jaxb) to generate java code from xml schema(xsd). I am adding customization using bindings. I would like to generate java code where all the variables are of the type String irrespective of their type in xsd i.e like xs:decimal, xs:date..etc
I tried using <xjc:javaType> while writing the binding but i need to provide an adapter to achieve that. I dont want to provide any adapter as the package generated will not have any other java code. This is what i want to do

<xjc:javaType name="java.lang.String" xmlType="xs:decimal"/>

Please note that it is not possible for me to change the schema.

役に立ちましたか?

解決

You could specify a binding file like the following and the XJC tool will auto-generate the necessary adapters.

<jxb:bindings 
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
    version="2.1">

   <jxb:bindings>
       <jxb:globalBindings>
           <jxb:javaType name="java.lang.String" xmlType="xs:int"/>
           <jxb:javaType name="java.lang.String" xmlType="xs:decimal"/>
       </jxb:globalBindings>
   </jxb:bindings>

</jxb:bindings>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top