Monday January 13, 2003
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
Matt Raible is the Lead UI Architect at LinkedIn. The opinions on this site are mine, not my employers.
Search This Site
Recent Entries
- EhCache Project Busy this Summer
- Spontaneous Stuff Weekend
- Awesome Birthday Present: A Kegerator
- Maven Plugin for Running Integration Tests against Multiple Containers
- Presenting Web Frameworks of the Future Tomorrow in Denver
- My OSCON Aftermath
- OSCON 2008 Wrapup
- [OSCON 2008] Even Faster Web Sites by Steve Souders
- [OSCON 2008] CSS for High Performance JavaScript UI by Gavin Doughtie
- [OSCON 2008] The State of Lightning Talks