Laurent Kloetzer created BEANUTILS-412:
------------------------------------------

             Summary: Default value is 0 instead of null for Integer properties
                 Key: BEANUTILS-412
                 URL: https://issues.apache.org/jira/browse/BEANUTILS-412
             Project: Commons BeanUtils
          Issue Type: Bug
          Components: Locale BeanUtils / Converters
    Affects Versions: 1.8.3
            Reporter: Laurent Kloetzer
             Fix For: 1.8.4


See the following test to see the problem and its solution.

public class Test {

        /**
         * @param args
         * @throws InvocationTargetException
         * @throws IllegalAccessException
         */
        public static void main(String[] args) throws IllegalAccessException, 
InvocationTargetException {
                test(false);
                test(true);

        }

        protected static void test(boolean withFix) throws 
IllegalAccessException, InvocationTargetException {
                Thing t1 = new Thing();
                t1.valInt = 1;
                t1.valInteger = 2;
                Thing t2 = new Thing();
                t2.valInt = 0;
                t2.valInteger = null;
                Thing t3 = new Thing();
                Thing t4 = new Thing();

                System.out.println(t2);
                System.out.println(t1);

                if (withFix) {
                        IntegerConverter ic = new IntegerConverter(null);
                        
BeanUtilsBean.getInstance().getConvertUtils().register(ic, Integer.class);
                }

                BeanUtilsBean.getInstance().copyProperties(t3, t1);
                BeanUtilsBean.getInstance().copyProperties(t4, t2);

                System.out.println(t4);
                System.out.println(t3);
        }

        public static class Thing {
                private int valInt;
                private Integer valInteger;

                @Override
                public String toString() {

                        return ToStringBuilder.reflectionToString(this);
                }

                public int getValInt() {
                        return valInt;
                }

                public void setValInt(int valInt) {
                        this.valInt = valInt;
                }

                public Integer getValInteger() {
                        return valInteger;
                }

                public void setValInteger(Integer valInteger) {
                        this.valInteger = valInteger;
                }

        }

}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to