On Wed, Dec 9, 2009 at 11:22 AM, Syed Muhammad Humayun <smhuma...@iblgrp.com> wrote: > Niall, > > Thanx for the help. I did following as a work around: > > PropertyUtils.getWriteMethod(PropertyUtils.getPropertyDescriptor(this, > propertyName)).invoke(this, new Object[]{null});
Why not just use PropertyUtils.setProperty(bean, propertyName, null); Niall > Regards, > > ----------------------------------------------- > S M Humayun > Software Architect, IBL Group > ----------------------------------------------- > Cell : 92.321.8707783 > Email (Official) : smhuma...@iblgrp.com > Email (Personal) : smhuma...@gmail.com > Google Talk : smhuma...@gmail.com > MSN : smhumayun2...@hotmail.com > Yahoo : humayun_repo...@yahoo.com > Skype : smhumayun > AIM : syedmohdhumayun > Blog : http://smhumayun.blogspot.com > LinkedIn : http://www.linkedin.com/in/smhumayun > Facebook : http://www.facebook.com/smhumayun > Twitter : http://twitter.com/smhumayun > Flickr : http://www.flickr.com/photos/smhumayun > YouTube : http://www.youtube.com/user/smhumayun > ----------------------------------------------- > -----Original Message----- > From: Niall Pemberton [mailto:niall.pember...@gmail.com] > Sent: Wednesday, December 09, 2009 4:18 PM > To: Commons Users List > Subject: Re: Setting null on Integer property via BeanUtils.setProperty > > On Wed, Dec 9, 2009 at 10:06 AM, Syed Muhammad Humayun > <smhuma...@iblgrp.com> wrote: >> Hi, >> >> How can I set a 'null' on Integer property (or any other wrappers like >> Double, Long, Character etc) via BeanUtils.setProperty? If its not >> possible this way than is there any other way using apache commons ? > > If you don't want "conversion" then you can use > org.apache.commons.beanutils.PropertyUtils.setProperty() method - but the > "value" object has to be the correct type (or null). > > For PropertyUtils see: http://tinyurl.com/yf9f6wk > > BeanUtils adds conversion to PropertyUtils - it tries to convert the value > you specified to the correct type of the the bean's property. > These converters have behaviour defined on how to handle "null" values and > operate in two modes: > - throw an exception > - use a default value > > The default set of converters which are "registered" with BeanUtils have a > default value specified - so for example the converter registered for > Integer types has a default value of zero. This is why you can't set a > "null" value at the moment. If you want null values to be set then you need > to register converter implementations for those types with a default value > of null. So for example you would do something like... > > ConvertUtils.register(new IntegerConverter(null), Integer.class); > ConvertUtils.register(new DoubleConverter(null), Double.class); > > (Note: the "null" value in the constructors is the default value) > > For ConvertUtils see: http://tinyurl.com/ydhq85s For converters see: > http://tinyurl.com/yl2pl2q > > Niall > >> Regards, > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscr...@commons.apache.org > For additional commands, e-mail: user-h...@commons.apache.org > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscr...@commons.apache.org > For additional commands, e-mail: user-h...@commons.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org