spring-framework / org.springframework.beans.propertyeditors / CustomCollectionEditor

CustomCollectionEditor

open class CustomCollectionEditor : PropertyEditorSupport

Property editor for Collections, converting any source Collection to a given target Collection type.

By default registered for Set, SortedSet and List, to automatically convert any given Collection to one of those target types if the type does not match the target property.

Author
Juergen Hoeller

Since
1.1.3

See Also
java.util.Collectionjava.util.Setjava.util.SortedSetjava.util.List

Constructors

<init>

CustomCollectionEditor(collectionType: Class<out MutableCollection<Any?>>)

Create a new CustomCollectionEditor for the given target type, keeping an incoming null as-is.

CustomCollectionEditor(collectionType: Class<out MutableCollection<Any?>>, nullAsEmptyCollection: Boolean)

Create a new CustomCollectionEditor for the given target type.

If the incoming value is of the given type, it will be used as-is. If it is a different Collection type or an array, it will be converted to a default implementation of the given Collection type. If the value is anything else, a target Collection with that single value will be created.

The default Collection implementations are: ArrayList for List, TreeSet for SortedSet, and LinkedHashSet for Set.

Functions

getAsText

open fun getAsText(): String

This implementation returns null to indicate that there is no appropriate text representation.

setAsText

open fun setAsText(text: String): Unit

Convert the given text value to a Collection with a single element.

setValue

open fun setValue(value: Any): Unit

Convert the given value to a Collection of the target type.