jaxb
  1. jaxb
  2. JAXB-961

xjc silenting ignores generating Enums when a numeric value is introduced

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.2.4u2
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      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.

        Activity

        Hide
        laune added a comment -

        An example of the input XSD that was expected to result in an enum and didn't sure would help...

        Show
        laune added a comment - An example of the input XSD that was expected to result in an enum and didn't sure would help...
        Hide
        ericpeters added a comment - - edited

        @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.

        Show
        ericpeters added a comment - - edited @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.

          People

          • Assignee:
            Iaroslav Savytskyi
            Reporter:
            ericpeters
          • Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: