commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Niall Pemberton <>
Subject Re: Setting null on Integer property via BeanUtils.setProperty
Date Wed, 09 Dec 2009 11:18:20 GMT
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:

View raw message