Reputation: 49
Using Java 17 and Gradle-plugin com.github.bjornvester.xjc' version '1.8.2
I want to generate java classes from an XSD schema. The java classes is to be used for values read from database. The values in DB can contain the non-ascii characters. Later the java object should be marshaled to a XML string, that validates.
And therefore the XSD contains non-ascii characters in enumerations (several places). Example:
<xsd:complexTypename="NyType">
<xsd:sequence>
<xsd:elementname="number"type="xsd:integer"/>
<xsd:elementname="myEnumType"type="MyEnumType"/>
</xsd:sequence>
</xsd:complexType>
<xsd:simpleTypename="MyEnumType">
<xsd:restrictionbase="xsd:string">
<xsd:enumerationvalue="ÄNt"/>
<xsd:enumerationvalue="Al-sör"/>
<xsd:enumerationvalue="Sår"/>
</xsd:restriction>
</xsd:simpleType>
This does not work. I get errors like:
error: unmappable character (0xF6) for encoding UTF-8
and
error: illegal character: '\ufffd'
The generated Java enum has
@XmlEnumValue("\u00c4Nt")
Ä_NT("\u00c4Nt"),
@XmlEnumValue("AL-s\u00f6r")
AL_SÖR("AL-s\u00f6r"),
I dont know how to solve this in a good way.
If I change all åäöÖÅÄ to aAoO in the XSD it works fine. But then the values from DB will not match then enum.
I have tried in the xjc bindingfile to change the enum by adding (example)
<jaxb:bindings node="//xsd:simpleType[@name='MyEnumType']/xsd:restriction/xsd:enumeration[@value='ÄNt']">
<jaxb:typesafeEnumMember name="ANT"/>
</jaxb:bindings>
With this the enum changes to
@XmlEnumValue("\u00c4Nt")
ANT("\u00c4Nt");
and the second error disapears, "unmappable character error" remains... The error points to a line in the generated javadoc-comment.
How do I replace the value in the enum as well? Or is it better to get xjc to not generate the enum values at all? Is so how to I configure that in the xjc bindingfile? Doing it like this doesn seem right..
<jaxb:bindings node="//xsd:simpleType[@name='MyEnumType']/xsd:restriction/xsd:enumeration[@value='ÄNt']">
<jaxb:typesafeEnumMember name=""/>
</jaxb:bindings>
If I get the xjc jaxb generation to pass, will it be possible to map to the correct values (as in DB) when generating XML from the java obejcts?
Upvotes: 0
Views: 88