Spring - Property Editors

[Last Updated: Jul 9, 2021]

Spring core framework uses PropertyEditor instances to convert text to other types and vice versa.

The PropertyEditor concept is part of the JavaBeans specifications.

PropertyEditor interface defines various methods, but getAsText() and setAsText(String) methods are used for conversion between String and other types.

Property Editors in Spring

In addition to property editors defined in JDK, Spring defines various property editors it's own.

Following is the list of property editors defined in org.springframework.beans.propertyeditors

  • org.springframework.beans.propertyeditors
    • ByteArrayPropertyEditor
    • CharArrayPropertyEditor
    • CharacterEditor
    • CharsetEditor
    • ClassArrayEditor
    • ClassEditor
    • CurrencyEditor
    • CustomBooleanEditor
    • CustomCollectionEditor
    • CustomDateEditor
    • CustomMapEditor
    • CustomNumberEditor
    • FileEditor
    • InputSourceEditor
    • InputStreamEditor
    • LocaleEditor
    • PathEditor
    • PatternEditor
    • PropertiesEditor
    • ReaderEditor
    • ResourceBundleEditor
    • StringArrayPropertyEditor
    • StringTrimmerEditor
    • TimeZoneEditor
    • URIEditor
    • URLEditor
    • UUIDEditor
    • ZoneIdEditor

[org.springframework:spring-context 5.3.12]

Following are the few of the cases where Spring uses PropertyEditor(s).

  • Setting Bean properties defined in XML configuration files. As all values of bean properties are in text format there, Spring needs to convert them into Java objects by using an appropriate PropertyEditor instance. For example if the target bean's 'property' is the java.lang.Class type then Spring uses ClassEditor (a Spring implementation of PropertyEditor).
  • In Spring MVC framework, all incoming HTTP request parameters and other information is in text, that's where PropertyEditors are also used for Java Object conversions.
  • By default fields annotated with @Value are implicitly converted by an appropriate property editor.

In next tutorials we are going to go through the important scenarios where we (as Spring Framework users) will likely be working with property editors.

See Also