xsd - JAXB globalBinding for anonymous enums -


i'm trying generate java classes using jaxb below xsd.

and had use below bindings file generate enum classes simple element derived xs:string , has enumeration facets. generates string instead...

(note: cannot change xsd)

see typesafeenumbase here

bindings.xjb file:

<jaxb:bindings         xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"         xmlns:xs="http://www.w3.org/2001/xmlschema"         xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"         jaxb:version="2.0">     <jaxb:globalbindings typesafeenummembername="generatename" typesafeenumbase="xs:string"/> </jaxb:bindings> 

test.xsd:

<?xml version="1.0" encoding="utf-8"?> <xs:schema      targetnamespace="http://www.example.com"       xmlns="http://www.example.com"       xmlns:xs="http://www.w3.org/2001/xmlschema">     <xs:element name="elementname">         <xs:simpletype>             <xs:restriction base="xs:string">                 <xs:enumeration value="my_enum_1"/>                 <xs:enumeration value="my_enum_2"/>             </xs:restriction>         </xs:simpletype>    </xs:element>     <xs:element name="root">         <xs:complextype>             <xs:sequence>                  <xs:element ref="elementname"/>             </xs:sequence>         </xs:complextype>     </xs:element> </xs:schema> 

command:

xjc -verbose test.xsd -b bindings.xjb 

generated java class:

root.java

you must add following bindings

<jaxb:bindings node="//xs:element[@name='elementname']/xs:simpletype">     <jaxb:typesafeenumclass name="elementname" /> </jaxb:bindings> 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -