List of utility methods to do Reflection Method Getter Get
Method | getGetterMethod(Class> clazz, String fieldName) get Getter Method String methodName = "get" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1); try { return getInheritMethod(clazz, methodName, new Class<?>[] {}); } catch (NoSuchMethodException e) { throw new RuntimeException(e); |
Method | getGetterMethod(Class> clazz, String methodNameWithoutGetPrefix) get Getter Method Method getterMethod = null; Method[] methods = clazz.getDeclaredMethods(); if (isNotEmpty(methods)) { for (Method method : methods) { if (method.getName().equals("get" + methodNameWithoutGetPrefix) && method.getGenericParameterTypes().length == 0) { getterMethod = method; break; ... |
Method | getGetterMethod(Class> clazz, String name) get Getter Method String methodName = convertToMehtodName("get", name); Method method = null; try { method = clazz.getMethod(methodName); } catch (Exception e) { throw new RuntimeException("get method exception - ", e); return method; ... |
Method | getGetterMethod(Class> clazz, String propertyName) get Getter Method final String camelCase = propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1); String getterName = "get" + camelCase; Method getterMethod; try { getterMethod = clazz.getMethod(getterName); } catch (Exception e) { getterName = "is" + camelCase; try { ... |
Method | getGetterMethod(String getterName, Object bean, Class> returnType) get Getter Method return getGetterMethod(getterName, bean.getClass(), returnType);
|
Method | getGetterMethodByProperty(String propertyName, Class> beanClass, Class> returnType) get Getter Method By Property Method getter = getGetterMethod(toGetterName(propertyName), beanClass, returnType); if (getter == null) { getter = getGetterMethod(toIsGetterName(propertyName), beanClass, returnType); return getter; |
Method | getGetterMethodForClass(Class cls, String beanName) Obtain a (Java bean) getter method from a class or superclasses using reflection. Method getter = findDeclaredMethodInHeirarchy(cls, getJavaBeanGetterName(beanName, false)); if (getter == null) { getter = findDeclaredMethodInHeirarchy(cls, getJavaBeanGetterName(beanName, true)); return getter; |
String | getGetterMethodName(String fieldName, java.lang.Class Get the getter method names for attributes. String firstStringChar = fieldName.substring(0, 1).toUpperCase(); String remaingString = fieldName.substring(1); String methodName = null; if (fieldType != null && fieldType == boolean.class || fieldType == Boolean.class) { methodName = "is" + firstStringChar + remaingString; } else { methodName = "get" + firstStringChar + remaingString; return methodName; |
String | getGetterMethodName(String property, String javaType) get Getter Method Name StringBuilder sb = new StringBuilder(); sb.append(property); sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); if (javaType.equals("boolean") || javaType.equals("Boolean") || javaType.equals("java.lang.Boolean")) { sb.insert(0, "is"); } else { sb.insert(0, "get"); return sb.toString(); |
List | getGetterMethodNames(Object o) get Getter Method Names List<String> methodNames = new ArrayList<>(); for (Method m : o.getClass().getMethods()) { if (m.getName().startsWith(GET_ROOT) || m.getName().startsWith(IS_ROOT)) { methodNames.add(m.getName()); return methodNames; |