Joda-Convert provides a small set of classes to aid conversion between Objects and Strings. It is not intended to tackle the wider problem of Object to Object transformation.
// conversion to String String str = StringConvert.INSTANCE.convertToString(foo); // conversion from String Foo bar = StringConvert.INSTANCE.convertFromString(Foo.class, str);
Joda-Convert supports two mechanisms of extending the list of supported conversions. The first is to write your own converter implementing an interface. The second is to use annotations.
The ability of Joda-Convert to use annotations to define the conversion methods is a key difference from other projects. For example, most value classes, like Currency or TimeZone, already have methods to convert to and from a standard format String. Consider a Distance class:
public class Distance { @FromString public static Distance parse(String str) { ... } @ToString public String getStandardOutput() { ... } }
As shown, the two methods may have any name. They must simply fulfil the required method signatures for conversion. The FromString annotation may also be applied to a constructor.
When Joda-Convert is asked to convert between an object and a String, if there is no registered converter then the annotations are checked. If they are found, then the methods are called by reflection.
Joda-Convert is licensed under the business-friendly Apache 2.0 licence.
Various documentation is available:
Release 1.3.1 is the current latest release. This release is considered stable and worthy of the 1.x tag. It depends on JDK 1.6 or later.
Available in the Maven Central repository.
Support on bugs, library usage or enhancement requests is available on a best efforts basis. If you have any questions, or want to volunteer to help, just email Stephen Colebourne via scolebourne.at.users.sourceforge.net.
To suggest enhancements or contribute, please fork the source code on GitHub. Alternatively, use GitHub issues.