org.apache.commons.beanutils.PropertyUtils.describe(Object )

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

org.apache.commons.beanutils.PropertyUtils.describe(Object )

Tamas Szabo
Hi,

I had some code which gets the properties of a bean and puts them in a Map.
Now I switched to Commons Beanutils, and I'm using
org.apache.commons.beanutils.PropertyUtils.describe(Object )
to do the same, but I learned that the Object.getClass() is considered a
getter, so I get a class property in the Map.
In my own code I explicitly checked that the properties are not comming
from java.lang.Object.

When I write a Bean I declare all the properties explicitly for it, but
because every object extends java.lang.Object
 ==> I will have a class property in all of my beans.

Is this the normal behaviour?
Should Object.getClass() be considered a getter and class a property of
every JavaBean?

Thanks,
Tamas


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: org.apache.commons.beanutils.PropertyUtils.describe(Object )

Grégory Joseph
Hi Tamas,

On 26/07/05, Tamas Szabo <[hidden email]> wrote:

> Hi,
>
> I had some code which gets the properties of a bean and puts them in a Map.
> Now I switched to Commons Beanutils, and I'm using
> org.apache.commons.beanutils.PropertyUtils.describe(Object )
> to do the same, but I learned that the Object.getClass() is considered a
> getter, so I get a class property in the Map.
> In my own code I explicitly checked that the properties are not comming
> from java.lang.Object.
>
> When I write a Bean I declare all the properties explicitly for it, but
> because every object extends java.lang.Object
>  ==> I will have a class property in all of my beans.
>
> Is this the normal behaviour?
> Should Object.getClass() be considered a getter and class a property of
> every JavaBean?
>

I'm not sure it should be considered a JavaBean property indeed, but
anyhow, in our project at worked, we simply created a dumb utility
method that removes the "class" property from the map. As a plus our
code, except that utility class, doesn't depend on beanutils,
anywhere.
(Actually, we needed this to get plain and dumb DTOs from entity EJBs,
so our util also removes references to the home interface etc.. from
the Map)

I suppose this doesn't really *help*, but maybe makes you more
confident in removing that property.

... but in the end, it all depends what you do with that Map.. All we
needed was something we could simply display in a jsp ;-)

Cheers,

g

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: org.apache.commons.beanutils.PropertyUtils.describe(Object )

Simon Kitching
In reply to this post by Tamas Szabo
On Tue, 2005-07-26 at 23:54 +0800, Tamas Szabo wrote:

> Hi,
>
> I had some code which gets the properties of a bean and puts them in a Map.
> Now I switched to Commons Beanutils, and I'm using
> org.apache.commons.beanutils.PropertyUtils.describe(Object )
> to do the same, but I learned that the Object.getClass() is considered a
> getter, so I get a class property in the Map.
> In my own code I explicitly checked that the properties are not comming
> from java.lang.Object.
>
> When I write a Bean I declare all the properties explicitly for it, but
> because every object extends java.lang.Object
>  ==> I will have a class property in all of my beans.
>
> Is this the normal behaviour?
> Should Object.getClass() be considered a getter and class a property of
> every JavaBean?

Yes, this is normal behaviour.

Try writing a simple test using the standard java.beans.Introspector
class and you will see that "class" is reported as a property of every
bean.

For a class SomeClass, try this:

    BeanInfo bi = Introspector.getBeanInfo(SomeBean.class);
    PropertyDescriptor[] props = bi.getPropertyDescriptors();
    for(PropertyDescriptor pd : props) {
      System.out.println("name: " + pd.getName());
      System.out.println("read: " + pd.getReadMethod());
      System.out.println("write: " + pd.getWriteMethod());
    }


Regards,

Simon


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]