Skip to content

Instantly share code, notes, and snippets.

@mnrasul
Created April 19, 2016 22:43
Show Gist options
  • Save mnrasul/afa932c33a01ebf1c97a1f263d55bbd4 to your computer and use it in GitHub Desktop.
Save mnrasul/afa932c33a01ebf1c97a1f263d55bbd4 to your computer and use it in GitHub Desktop.
// read a value
Object value = new PropertyDescriptor(property, clazz).getReadMethod().invoke(object);
//write a value
/**
*
* @param className
* @param valueToSet
* @param property
* @throws Exception
*/
public static Object setStringValue(String className, String valueToSet, String property) throws Exception {
property = UppercaseFirstCharacter(property);
Class clazz = Class.forName(className);
Object object = clazz.newInstance();
String []inputArray = {valueToSet};
Statement set = new Statement(object, "set"+property, inputArray);
set.execute();
return object;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment