You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Brian Knorr <bt...@nextjet.com> on 2002/10/31 23:12:41 UTC

ConvertUtils.convert(Object) doesn't use registered convertor

Tried sending this to commons-user mailing list several times now, but
haven't gotten a response... thought I would try the dev list instead...

The following is a detailed description of what we have found... any
help is greatly appreciated:

Looking at the commons-beanutils source you will find the following
method on BeanUtils.java:

    public static String getNestedProperty(Object bean, String name)
            throws IllegalAccessException, InvocationTargetException,
            NoSuchMethodException {

        Object value = PropertyUtils.getNestedProperty(bean, name);
        return (ConvertUtils.convert(value));
    }

***Please notice that it calls ConvertUtils.convert(value) - here is the
source for that method:

    public static String convert(Object value) {
        if (value == null) {
            return ((String) null);
        } else if (value.getClass().isArray()) {
            if (Array.getLength(value) < 1) {
                return (null);
            }
            value = Array.get(value, 0);
            if (value == null)
                return ((String) null);
            else
                return (value.toString());
        } else {
            return (value.toString());
        }
    }

***As one can see the convert method never tries to use a registered
convertor... is this a bug or its intended behavior?  When calling
getProperty, getNestedProperty, or getSimpleProperty on BeanUtils.java
we would like to have our registered convertor convert the Object to a
String rather than the system calling toString.  Please advise...

Thanks,

Brian

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>