Created
August 11, 2010 12:11
-
-
Save bherrmann7/518889 to your computer and use it in GitHub Desktop.
Java code for finding properties (is/get/set pairs)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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