Beanutils converter sets the default value of long, integer and other fields to null

Source: Internet
Author: User

Today, when using beanutils, we found that the original field is null when the copyproperties method is copied from long to long. After the result is copied, the target field is changed to 0, which is not the expected result, after searching online, you can use the converter to set the default conversion value when it is null.

Static {convertutils. register (New longconverter (null), long. class); convertutils. register (new vertex converter (null), short. class); convertutils. register (New integerconverter (null), integer. class); convertutils. register (New doubleconverter (null), double. class); convertutils. register (New bigdecimalconverter (null), bigdecimal. class );}

So I set the default conversion value of some commonly used numeric fields to null, and then use beanutils. if the copyproperties copy field, long, integer, and other fields are null, they will not be converted to 0 by default.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.