Converts a type to its string representation and back.
Converts a type to its string representation and back.
For creation of the type from a string the create_...
methods are used.
Automatically supported types are: $ - collection types (immutable preferred): List, Seq, Vector, Set $ - all classes deriving from Product, including case classes and tuples
If a new type NewType
shall be supported, the TypeConversions has to be extended with the create_NewType(str: String)
method.
The conversion to a string is simply done by calling the object's toString method - Strings themselves are surrounded by quotes.
If a new type (or an existing one) shall change the conversion to a string, the appendString(Any, StringBuilder)-method has to be overridden.
Example: extend TypeConversions for java.io.File
, where its String representation is mapped to the file's absolute path
val config = ConfigMacros.wrap(classOf[Config], props.getProperty, props.setProperty, new TypeConversions { def create_File(filename: String) = new File(filename) override def appendString(any: Any, buf: StringBuilder) { any match { case file: File => buf.append(file.getAbsolutePath) case any => super.appendString(any, buf) } } })
Contains the classes necessary to convert the configuration objects to strings and back.