Converters
back to index
Converters are classes that implement the (
IConverter) and that provide conversion facilities from one data type to another. Converters must be thread-safe, since only one instance is created for all the conversions that a particular converter can handle. Currently, dynject can handle the following conversions automatically:
- From any numeric type to any other numeric type, including BigDecimals and BigIntegers
- From any type to String
- From any type to StringBuffer
- From any type to StringBuilder
- From any numeric type to java.util.Date and java.sql.Date (the number is interpreted as UTC)
- From any date-type to any other date-type (date type = Date/Time/Timestamp/Calendar)
- From any date-type to long, Long, BigInteger and BigDecimal (Utc value will be stored)
- From any CharSequence to any enumerated type.
- From any CharSequence to java.util.Date and java.sql.Date (using the yyyy-MM-dd pattern)
- From any CharSequence to java.sql.Time (using the HH:mm:ss pattern)
- From any CharSequence to java.sql.Timestamp (using the yyyy-MM-dd HH:mm:ss pattern)
- From any CharSequence to Calendar (using the previous date /time pattern)
- From any CharSequence to any class having a single-parameter string constructor (for example : URL, File, etc.)
All the converters are instantiated at startup and registered in a global cache. This is handled by the
Converters class
Although the default converters are usually fine, there are occasions in which you'd want to use converting annotations that allow you to specify a different pattern (especially true for dates and times)