Init all Bean properties
I'm working at the moment on some POJOs which are containing a huge bunch of properties. I have to ensure that all properties are initialized. Are there some util classes which could handle this for me at runtime?
A superb 开发者_如何学Gofeature would be to check for null value and init to default value.
You can use Apache Commons BeanUtils to do this. Assuming that your POJOs follow the Java Bean naming conventions for properties and getter/setter methods, if have your property values in a Map
you can use BeanUtils.populate
to populate beans with a predefined set of property values. If you want to copy values from one bean to another, use BeanUtils.copyProperties
.
精彩评论