1. CXF
  2. CXF-2390

Enums using fromString() but jaxb creates fromValue()


    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.2.2
    • Fix Version/s: 2.2.4, 2.3
    • Component/s: JAX-RS
    • Labels:
    • Environment:

      CXF version 2.2.2
      Jaxb version 2.1.9 ? Not positive on this


      Let's say you have an xsd file that defines an enum.

      <xs:simpleType name="timezone">
      <xs:restriction base="xs:string">
      <xs:enumeration value="Europe/London" />
      <xs:enumeration value="America/New_York" />

      When xjc (jaxb) runs and creates a Java enum for this, it gives the Enum instances slightly different names, but makes the underlying value available.

      @XmlType(name = "timezone")
      public enum Timezone {


      It also creates a "fromValue()" method to retrieve an enum instance given the value.

      Now say that you want to create a REST web service that has a Timezone as a QueryParam

      public Result theTest(@QueryParam("timezone") Timezone timezone)

      If you attempt to call this REST method with a timezone of "Europe%2FLondon", you'll get an exception java.lang.IllegalArgumentException: No enum const class beans.Timezone.Europe/London
      at org.apache.cxf.jaxrs.utils.InjectionUtils.evaluateFactoryMethod(
      at org.apache.cxf.jaxrs.utils.InjectionUtils.handleParameter(
      at org.apache.cxf.jaxrs.utils.InjectionUtils.createParameterObject(
      at org.apache.cxf.jaxrs.utils.JAXRSUtils.readQueryString(

      The InjectionUtils class has this logic:

      // check for valueOf(String) static methods
      String[] methodNames = pClass.isEnum()
      ? new String[]

      {"fromString", "valueOf"}

      : new String[]

      {"valueOf", "fromString"}

      Object result = evaluateFactoryMethod(value, pClass, pType, methodNames[0]);
      if (result == null)

      { result = evaluateFactoryMethod(value, pClass, pType, methodNames[1]); }

      Note that in the case of an Enum, it is trying to call "fromString()" (which doesn't exist), and failing that, it tries to call "valueOf()", which would work if the client had passed EUROPE_LONDON as the value.

      Perhaps different versions of xjc/jaxb create fromValue and some create fromString(). I'm not sure. But clearly some versions of jaxb create a method called fromValue().

      The net result is that the service doesn't actually work if you pass it the value as defined in the restriction. Can injection utils be changed to include an attempt to use fromValue() as well?


        No work has yet been logged on this issue.


          • Assignee:
            Sergey Beryozkin
            David Wood
          • Votes:
            0 Vote for this issue
            0 Start watching this issue


            • Created: