Question: At the moment I am doing this in each controller i need it :

```
 @InitBinder
 protected void initBinder(WebDataBinder binder){
   binder.registerCustomEditor(
     Country.class, new CountryPropertyEditor(this.countryService));
 }

```

Which works fine converting my string variable to country, however is there a way I can register this with all controllers ?

Answer: 
To register custom property editor once for whole application override **addFormatters** method of **WebMvcConfigurerAdapter** in your configuration class. 

Example for date (with Java config)

```
@EnableWebMvc
@Configuration
public class WebConfiguration extends WebMvcConfigurerAdapter {

    // ...

    @Override
    public void addFormatters( final FormatterRegistry registry ) {
        registry.addFormatterForFieldType( java.sql.Date.class, new DateFormatter() );
    }

    // ... 
}

```

and make your own class for date formatting which implements **Formatter** interface, something like this 

```
public final class DateFormatter implements Formatter<java.sql.Date> {

    private String pattern;

    public DateFormatter() {
        this( "yyyy-MM-dd" );
    }

    public DateFormatter( final String pattern ) {
        this.pattern = pattern;
    }

    public String print( final java.sql.Date date, final Locale locale ) {
        if ( date == null ) {
            return "";
        }
        return getDateFormat( locale ).format( date );
    }

    public java.sql.Date parse( final String formatted, final Locale locale ) throws
        ParseException {
        if ( formatted.length() == 0 ) {
            return null;
    }
    java.util.Date udDate = getDateFormat( locale ).parse( formatted );
    return new java.sql.Date( udDate.getTime() );
}

protected DateFormat getDateFormat( final Locale locale ) {
    DateFormat dateFormat = new SimpleDateFormat( this.pattern, locale );
    dateFormat.setLenient( false );
    return dateFormat;
}

```

}

That's it.
You can register property editors declaratively in xml configuration file so it's used as needed in the presentation layer:

First register the class being used for the conversion:

```
<bean id="sample" class="youpackages.SophisticatedClass">
    <property name="type" value="sophisticatedClass"/>
</bean>

```

Then register it globally in the application:

```
<bean class="org.springframework.beans.factory.config.CustomEditorConfigurer">
  <property name="customEditors">
    <map>
      <entry key="youpackages.SophisticatedClass" value="yourpackages.SophisticatedClassEditor"/>
    </map>
  </property>
</bean>

```

This way, as soon as a conversion related to the "Sophisticated" class is needed, the property editor will be used as it has been registered in the application context.

This way you don't have to get your model tight to the fact that this conversions are needed.

Hope it helps!