[
https://issues.apache.org/jira/browse/BEANUTILS-317?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Niall Pemberton resolved BEANUTILS-317.
---------------------------------------
Resolution: Invalid
Questions like this should really be asked on the user mailing list, rather
than using the Bug tracking system.
BeanUtils uses the registered converter for the type to convert to the
appropriate type. So you need to either configure the converter with a default
value of null - or using PropertyUtils (which doesn't try to convert) instead:
So for the Converter solution, do the following:
ConvertUtils.register(new IntegerConverter(null), Integer.class);
... or use PropertyUtils
PropertyUtils.setProperty(foo, "num", null);
> BeanUtils.setProperty does not seem to be able to set a null value on a
> java.lang.Integer
> -----------------------------------------------------------------------------------------
>
> Key: BEANUTILS-317
> URL: https://issues.apache.org/jira/browse/BEANUTILS-317
> Project: Commons BeanUtils
> Issue Type: Bug
> Components: Bean / Property Utils
> Affects Versions: 1.6, 1.6.1, 1.7.0, 1.8.0-BETA
> Environment: Java 1.6
> Reporter: Tj Zecca
>
> I get the following unexpected results:
> INITIAL STATE: null
> AFTER SETTER: 5
> AFTER BeanUtils.setProperty: 0
> Using the following code:
> public static void main(String[] args) {
> SimpleBean bean = new SimpleBean();
> System.out.println("INITIAL STATE: " + bean.getNum());
> bean.setNum(new Integer(5));
> System.out.println("AFTER SETTER: " + bean.getNum());
> try {
> BeanUtils.setProperty(bean, "num", null);
> System.out.println("AFTER BeanUtils.setProperty: " + bean.getNum());
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
> public class SimpleBean {
> private Integer num;
> public Integer getNum() {
> return this.num;
> }
> public void setNum(Integer num) {
> this.num = num;
> }
> }
> PS. I have also tested with the Boolean primitive wrapper and it does not set
> null either.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.