I have web application written in Java. Im using BeanUtils.copyProperties method. If a date field is null, it throws an error. I solved it by using ConvertUtils.register method.
ConvertUtils.register(new DateConverter(null), Date.class);
It works now, but what is the correct way of using ConvertUtils.register. Where should it be placed?
What you have done is CORRECT for only one class(Date) type. This is achieved for all the supported types including Date by calling register method on
ConvertUtilsBeanas below:Here, first argument
falsemeans don’t throw conversion exception. Second argumenttruerepresents, if there is exception, use null as default value. Third argument-1represent that array types will be defaulted to null. If you want to default arrays with specific size, mention the size as third parameter.Refer more details here (ConvertUtilsBean Javadoc).