Jodd is an open-source java library with lot of reusable components and feature rich utilities.
This requires the library jodd-3.3.2.jar to be in classpath.
The following example shows how to set declared bean property value by property name
using BeanUtil.setDeclaredProperty() API.
If a setter method exists for a given property then it uses the same otherwise accesses the
//Tries to invoke the setter method for given property
//If not found sets the field directly.
BeanUtil.setDeclaredProperty(std, "name", "Sriram");
BeanUtil.setDeclaredProperty(std, "age", 2);
BeanUtil.setDeclaredProperty(std, "hobby", "Chess");
It gives the following output,
In setName method with name : Sriram
Student[name = Sriram, age = 2, hobby = Chess]