Skip to content
zhaber edited this page Jul 28, 2012 · 2 revisions

Converter is a function that sanitizes a value of a parameter according to the context in which it will be used, reduces the value to a canonical form acceptable by a main application, or applies some other custom transformations. The simplest example would be a trim function that removes spaces before and after the value:

String trim(String value) { 
   value.trim() 
}

Another example would be a converter for a postal code that, for example, transforms k1A 0j9 into K1A0J9.

A converter can also take regular parameters:

String toDate(String date, String format) {
   //...
}

It can return a value of any type including dynamic (def). Both converters and validators can be overloaded or overridden.