Damn Java Gotchas
1. Commons BeanUtils.populate() is a very useful function but it
- does not set public properties
- will not call a setter method if its return type is not void
So if your class has a nicely chained setter method like
MyClass setFoo(String s) { this.foo = s; return this; }
this test will fail
map.put( "foo", "bar" );
BeanUtils.populate( myobj, map );
assertNotNull( myobj.getFoo() ); // fail!!
BeanUtils says “mmm, let’s see… I have a key ‘foo’ in my map and a ‘setFoo’ method on the class…mmm…let’s see…not sure what to do, so er, I won’t do anything at all”.