Skip to content

Instantly share code, notes, and snippets.

@bherrmann7
Created August 11, 2010 12:11
Show Gist options
  • Save bherrmann7/518889 to your computer and use it in GitHub Desktop.
Save bherrmann7/518889 to your computer and use it in GitHub Desktop.
Java code for finding properties (is/get/set pairs)
// Java code for finding properties (is/get/set pairs)
for(Method method: bean1.getClass().getMethods()){
if(method.getDeclaringClass()!=AccountRequest.class || !(method.getName().startsWith("get") || method.getName().startsWith("is")) || method.getTypeParameters().length!=0)
continue;
String propName = method.getName().substring(2,method.getName().length());
if(method.getName().startsWith("get")){
propName = method.getName().substring(3,method.getName().length());
}
Method setter = null;
try {
setter = bean1.getClass().getMethod("set"+propName, method.getReturnType());
} catch (NoSuchMethodException e) {
continue;
}
System.out.println("//Found Property: "+propName);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment