Custom Enum Converter is being instantiated but not called
<p>I have the following problem:</p>

<p>A team-member changed the sensa/ext js front end and is sending a parmeter with a space instead of an underscore. I don't know the front-end code of the project as well, and this is causing the following error:</p>

<pre><code>Caused by: org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type @org.springframework.web.bind.annotation.RequestParam org.company.project.persistence.enums.DocumentTypeEnum for value 'EXPERT OPINION'; nested exception is java.lang.IllegalArgumentException: No enum constant org.company.project.persistence.enums.DocumentTypeEnum.EXPERT OPINION
</code></pre>

<p>I changed a get parameter of the request using fiddler and I saw that the problem is that <code>EXPERT OPINION</code> is being sent instead of <code>EXPERT_OPINION</code>.</p>

<p>Initially, I added a <code>filter</code> and tried changing the get parameter value, but I had to add a wrapper since you cannot modify http requests directly. However, the underlying converter seems to get the <code>parameter</code> value directly from the original http request so this failed.</p>

<p>Then I decided to try making a custom converter. I have made the following class that is instantiated when I run the project, but it is never called to perform the specific conversion:</p>

<pre><code>@Configuration
public class EnumCustomConversionConfiguration {

    @Bean
    public ConversionService getConversionService() {
        ConversionServiceFactoryBean bean = new ConversionServiceFactoryBean();
        bean.setConverters(getConverters());
        bean.afterPropertiesSet();
        ConversionService object = bean.getObject();
        return object;
    }

    private Set&lt;Converter&gt; getConverters() {
        Set&lt;Converter&gt; converters = new HashSet&lt;Converter&gt;();

        converters.add(new StringToEnumConverter(DocumentTypeEnum.class));

        return converters;
    }

    @SuppressWarnings("rawtypes")
    private final class StringToEnumConverter&lt;T extends Enum&gt; implements Converter&lt;String, T&gt; {

        private final Class&lt;T&gt; enumType;

        public StringToEnumConverter(Class&lt;T&gt; enumType) {

            this.enumType = enumType;
        }

        @SuppressWarnings("unchecked")
        public T convert(String source) {

            checkArg(source);
            return (T) Enum.valueOf(enumType, source.trim());
        }

        private void checkArg(String source) {

            // In the spec, null input is not allowed
            if (source == null) {
                throw new IllegalArgumentException("null source is in allowed");
            }
        }
    }

}
</code></pre>