title: Convert String to Enum using Apache BeanUtils
body: <p>I've implemented a converter for Apache BeanUtils library for converting String to an enum constant:</p>
  
  <pre><code>class EnumConverter implements Converter {    
      @Override
      public &lt;T&gt; T convert(Class&lt;T&gt; tClass, Object o) {
          String enumValName = (String) o;
          Enum[] enumConstants = (Enum[]) tClass.getEnumConstants();
  
          for (Enum enumConstant : enumConstants) {
              if (enumConstant.name().equals(enumValName)) {
                  return (T) enumConstant;
              }
          }
  
          throw new ConversionException(String.format("Failed to convert %s value to %s class", enumValName, tClass.toString()));
      }
  }
  </code></pre>
  
  <p>I use it in the following way:</p>
  
  <pre><code>// Register my converter    
  ConvertUtils.register(new EnumConverter(), Enum.class);
  Map&lt;String, String&gt; propMap = new HashMap&lt;String, String&gt;();
  // fill property map    
  BeanUtils.populate(myBean, propMap);
  </code></pre>
  
  <p>Unfortunatelly a setter in myBean instance except ConcreteEnumClass enum, instead of java.lang.Enum, that is why I receive the following exception during BeanUtils.populate method call:</p>
  
  <pre><code>org.apache.commons.beanutils.ConversionException: Default conversion to ConcreteEnumClass failed.
      at org.apache.commons.beanutils.converters.AbstractConverter.handleMissing(AbstractConverter.java:314)
      at org.apache.commons.beanutils.converters.AbstractConverter.handleError(AbstractConverter.java:269)
      at org.apache.commons.beanutils.converters.AbstractConverter.convert(AbstractConverter.java:177)
      at org.apache.commons.beanutils.converters.ConverterFacade.convert(ConverterFacade.java:61)
      at org.apache.commons.beanutils.ConvertUtilsBean.convert(ConvertUtilsBean.java:491)
      at org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1000)
      at org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:821)
      at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:431)
  </code></pre>
  
  <p>If I register EnumConverter in the following way:</p>
  
  <pre><code>ConvertUtils.register(new EnumConverter(), ConcreteEnumClass.class);
  </code></pre>
  
  <p>Everything woks perfectly.</p>
  
  <p>Since I would like to use my EnumConverter in general case, I would prefer it be used to convert String to any enum class.</p>
  
  <p>Is it possible? How should I do it?</p>