Monday January 13, 2003
Loading Twitter updates 
Follow me on Twitter

ConvertUtils problem solved! I got the solution to my ConvertUtils problem from the hibernate-devel mailing list. Thanks to Juozas Baliuka! Here's my new convert method:
public Object convert(Class type, Object value) {
if (log.isDebugEnabled()) {
log.debug("entering 'convert' method");
}
// for a null value, return null
if (value == null) {
return null;
} else if (value.getClass().isAssignableFrom(type)) {
return value;
} else if (ArrayList.class.isAssignableFrom(type)
&& (value instanceof Collection)) {
return new ArrayList((Collection) value); // List, Set, Collection -> ArrayList
} else if (type.isAssignableFrom(Collection.class)
&& (value instanceof Collection)) {
try {
//most of collections implement this constructor
Constructor constructor =
type.getConstructor(new Class[] { Collection.class });
return constructor.newInstance(new Object[] { value });
} catch (Exception e) {
log.error(e);
}
}
throw new ConversionException("Could not convert "
+ value.getClass().getName() + " to "
+ type.getName() + "!");
}
Posted in Java
at Jan 13 2003, 09:15:09 AM MST
Add a Comment
Search This Site
Recent Entries
- Secure JSON Services with Play Scala and SecureSocial
- My What's New in Spring 3.1 Presentation
- Twitter's Open Source Summit: Bootstrap 2.0 Edition
- Refreshing AppFuse's UI with Twitter Bootstrap
- 2011 - A Year in Review
- Upgrading AppFuse to Spring Security 3.1 and Spring 3.1
- What have I been working on at Taleo?
- Our Engaging Trip to Paris and Antwerp
- My HTML5 with Play Scala, CoffeeScript and Jade Presentation from Devoxx 2011
- Deploying Java and Play Framework Apps to the Cloud with James Ward