According to the link
If typesafeEnumBase is set to xsd:string, it would be a global way to specify that all simple type definitions deriving directly or indirectly from xsd:string and having enumeration facets should be bound by default to a typesafe enum. If typesafeEnumBase is set to an empty string, "", no simple type definitions would ever be bound to a typesafe enum class by default. The value of typesafeEnumBase can be any atomic simple type definition except xsd:boolean and both binary types.
So I have set to my binding.xjb
the following:
<jxb:globalBindings typesafeEnumBase=""/>
and when running the jaxb2-maven-plugin
I get the following exception:
lineNumber: 5; columnNumber: 46; cvc-minLength-valid: Value '' with length = '0' is not facet-valid with respect to minLength '1' for type '#AnonType_typesafeEnumBaseglobalBindings'.
...
lineNumber: 5; columnNumber: 46; cvc-attribute.3: The value '' of attribute 'typesafeEnumBase' on element 'jxb:globalBindings' is not valid with respect to its type, 'null'.
As far as I understand I cannot set the empty string ""
to typesafeEnumBase
even though the documentation says so. Documentation also mentions that it cannot be xsd:boolean
.
All I want is to convert the following to String
instead of enum
<xs:simpleType name="phraseID">
<xs:restriction base="escapedStringUserType">
<xs:enumeration value="NOT_SPECIFIED"/>
<xs:enumeration value="X000-9999"/>
<xs:enumeration value="X000-9998"/>
</xs:restriction>
</xs:simpleType>
A relevant SO question is here but since I cannot set the empty string ""
or set the xsd:boolean
value to typesafeEnumBase
none of the answers work for me (tried both).
Setting the following
will not generate any enums for all simple types with enumeration restrictions instead will convert them to strings, however it spits out warnings in the console like the following:
You can specify for a specific simple type with enumeration restrictions that you do not want it to be mapped to a Java
enum
like in this example:But as far as I know, there is no way to set this globally for all simple types with enum restrictions (you cannot use
<jaxb:typesafeEnumClass map="false"/>
directly inside a<jaxb:globalBindings>
, for example).(If someone knows how to do this, I'd like to know as well, so please comment or answer).