commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Syed Muhammad Humayun" <>
Subject RE: Setting null on Integer property via BeanUtils.setProperty
Date Wed, 09 Dec 2009 11:22:37 GMT

Thanx for the help. I did following as a work around:

propertyName)).invoke(this, new Object[]{null});


S M Humayun
Software Architect, IBL Group
Cell : 92.321.8707783
Email (Official) :
Email (Personal) :
Google Talk :
Yahoo :
Skype : smhumayun
AIM : syedmohdhumayun
Blog :
LinkedIn :
Facebook :
Twitter :
Flickr :
YouTube :
-----Original Message-----
From: Niall Pemberton [] 
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
<> 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:

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: For converters see:


> Regards,

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message