jaxb-ri icon indicating copy to clipboard operation
jaxb-ri copied to clipboard

xjc silenting ignores generating Enums when a numeric value is introduced

Open Tomas-Kraus opened this issue 11 years ago • 6 comments

I had an original XSD that was created that had a Enum created and I was using it.

With an updated XSD I was given, I updated the jar files with xjc only to find out the Enum was no longer being created. Even with the -verbose flag there was no indication of what the problem was.

After lots of beating my head against the wall, I finally found: typesafeEnumMemberName="generateError" and that helped isolate what the problem was.

The default xjc really should have some type of warning/info message - especially when -verbose is specified.

Affected Versions

[2.2.4u2]

Tomas-Kraus avatar May 22 '13 18:05 Tomas-Kraus

  • Issue Imported From: https://github.com/javaee/jaxb-v2/issues/961
  • Original Issue Raised By:@glassfishrobot
  • Original Issue Assigned To: @glassfishrobot

Tomas-Kraus avatar Sep 21 '18 16:09 Tomas-Kraus

@glassfishrobot Commented Reported by ericpeters

Tomas-Kraus avatar May 22 '13 18:05 Tomas-Kraus

@glassfishrobot Commented laune said: An example of the input XSD that was expected to result in an enum and didn't sure would help...

Tomas-Kraus avatar May 22 '13 19:05 Tomas-Kraus

@glassfishrobot Commented ericpeters said: @Iaune:

The orginal XSD looked something like:

<xs:simpleType name="AssetType">
		<xs:annotation>
			<xs:documentation>...
			</xs:documentation>
		</xs:annotation>
		<xs:restriction base="xs:string">
			<xs:length value="3"/>
			<xs:enumeration value="APG"/>
			<xs:enumeration value="AUD"/>
			<xs:enumeration value="BRO"/>
...
		</xs:restriction>
	</xs:simpleType>

XJC generated an enum like

@XmlType(name = "AssetType")
@XmlEnum
public enum AssetType {

    APG("APG"),
    AUD("AUD"),
....

The updated XSD had:

<xs:simpleType name="AssetType">
		<xs:annotation>
			<xs:documentation>...
			</xs:documentation>
		</xs:annotation>
		<xs:restriction base="xs:string">
			<xs:length value="3"/>
			<xs:enumeration value="360"/>
			<xs:enumeration value="APG"/>
			<xs:enumeration value="AUD"/>
			<xs:enumeration value="BRO"/>
		</xs:restriction>
	</xs:simpleType>

After running xjc on the updated XSD, my client code was broken, since the Enum didn't exist. Ultimately it was the numeric value 360 that isn't valid for an enum variable name that was the culprit. However, even with -verbose settings it was not clear, since there was no warning/info message/etc, that xjc found an invalid enum value and was simply skipping the generation of the Enum and getting/setting Strings directly instead in the generated class.

The work around I finally found was to add into the bindings:

<!-- AssetType Numeric Enum Values -->
        <jaxb:bindings node="//xsd:simpleType[@name='AssetType']/xsd:restriction/xsd:enumeration[@value='360']">
            <jaxb:typesafeEnumMember name="ThreeSixty"/>
        </jaxb:bindings>

It was very frustrating determining why XJC wasn't generating the same classes that it had generated before.

Tomas-Kraus avatar May 22 '13 19:05 Tomas-Kraus

@glassfishrobot Commented Was assigned to yaroska

Tomas-Kraus avatar May 22 '13 18:05 Tomas-Kraus

@glassfishrobot Commented This issue was imported from java.net JIRA JAXB-961

Tomas-Kraus avatar Apr 24 '17 12:04 Tomas-Kraus