简体   繁体   中英

errors in classes generated by JAXB from XSD

I use JAXB in eclipse Luna to generate Java classes from a third party XSD file. This file often defines a simple type which is just a primitive type. For instance:

<xsd:simpleType name="ChannelIdType">
  <xsd:restriction base="xsd:unsignedInt" />
</xsd:simpleType>

The simple type is then used for elements of a complex type, for instance:

<xsd:complexType name="DataRequestEntryType">
  <xsd:sequence>
    <xsd:element name="ChannelId" type="ChannelIdType" />
    <xsd:element name="IsChannelOpen" type="xsd:boolean" />
    ...
  </xsd:sequence>
</xsd:complexType>

JAXB generates a Java class for the complex type that seems perfectly correct:

public class DataChannelEntryType {
  @XmlElement(name = "ChannelId")      <-- ERROR here, see below
  protected long channelId;
  @XmlElement(name = "IsChannelOpen")
  protected boolean isChannelOpen;
  ...
}

But, it also generates the following JAXB ERROR for the line @XmlElement(name = "ChannelId")

The expected XML type associated with 'long' is not valid for XML element 'ChannelId'.

Does anybody know what that error message means? I cannot change the XSD file, but what should one do to remove the error (short of removing the simple class, which anyway seems quite legal)? Or at least suppress the generation of the error?

Any help will be greatly appreciated!

Try disabled JAXB Validator.

Project -> Properties -> Validation -> Jaxb Validator

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM