jaxb
  1. jaxb
  2. JAXB-989

Java's JAXB implementation does not handle underscores properly

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.2.7
    • Fix Version/s: None
    • Component/s: xjc
    • Labels:
      None

      Description

      The usecase to recreate the issue is to try and translate the following schema to java:

      <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
      <xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:complexType name="Foo_Bar">
      <xs:sequence>
      <xs:element name="name" type="xs:string" minOccurs="0"/>
      <xs:element name="choices" type="TypeMyEnum" minOccurs="0"/>
      </xs:sequence>
      </xs:complexType>
      <xs:simpleType name="TypeMyEnum">
      <xs:restriction base="xs:string">
      <xs:enumeration value="ALPHA_1_0_0"/>
      <xs:enumeration value="BETA_2_0_0"/>
      </xs:restriction>
      </xs:simpleType>
      </xs:schema>

      By default, xjc will create a file called FooBar.java and a file called TypeMyEnum.java. Notice how xjc "ate" the underscore in Foo_Bar. Also, by default, the internals of TypeMyEnum look like this:

      ALPHA_1_0_0,
      BETA_2_0_0;

      To get the underscore back in Foo_Bar, one has to use a bindings file as follows:

      <jxb:bindings version="1.0"
      xmlns:jxb="http://java.sun.com/xml/ns/jaxb">
      <jxb:globalBindings underscoreBinding="asCharInWord"/>
      </jxb:bindings>

      Now, the code generates a Foo_Bar.java file as desired but horribly changes the internals of TypeMyEnum to look like:

      @XmlEnumValue("ALPHA_1_0_0")
      ALPHA__1_0__0("ALPHA_1_0_0"),

      @XmlEnumValue("BETA_2_0_0")
      BETA__2_0__0("BETA_2_0_0");
      private final String value;

      It seems every underscore in an enum value is changed to three underscores. This is the issue. This is easily reproducible and beyond me why xjc would do this.

      There is no known way to get xjc to retain the underscore in the class name (i.e Foo_Bar.java) AND generate a sane enum file.

        Activity

        There are no comments yet on this issue.

          People

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

            Dates

            • Created:
              Updated:

              Time Tracking

              Estimated:
              Original Estimate - 2 days
              2d
              Remaining:
              Remaining Estimate - 2 days
              2d
              Logged:
              Time Spent - Not Specified
              Not Specified