Type conversion made easy
In strongly typed languages, like Java, conversion between multiple types can be really painful. How many times did you forget how to convert
Calendar? How about conversion between collections? The operation is often performed in multiple lines of code and in no time you find yourself focusing on the type juggling instead of problem solving.
That’s why we came up with TypeConverter. It’s a utility class that makes type conversion very easy. It’s very fast and extendable.
convert() method with object and expected type as parameters.
so for example to convert
It’s always short and easy.
What conversions are supported
Multiple conversions are supported out of the box. Take a look at the following list:
All primitives are also supported so you don’t have to worry about boxing.
Your type is not on the list? You can easily “teach”
TypeConverter new conversion.
To create new converter just create a class that implements
Converter interface, i.e.:
And pass it to the
To make it more readable you can use anonymous class:
TypeConverter is also lambda friendly so if you are using java 8 in your project it gets as simple as:
It’s worth to note that our newly registered converter from Object.class to String.class will override any already registered converter that supports the same conversion.
As registering converters is very easy, unregistering them is even easier:
How do I get this?
We’re on Maven Central so just add this to your