コード例 #1
0
  private static Set<MethodInfo> getGetterMethodInfo(Class<?> clazz) {

    Set<MethodInfo> methodInfos = METHOD_MAP.get(clazz);

    if (methodInfos == null) {

      methodInfos = new HashSet<MethodInfo>();

      boolean includeSuperClass = clazz.getClassLoader() != null;

      Method[] methods = includeSuperClass ? clazz.getMethods() : clazz.getDeclaredMethods();

      for (Method method : methods) {
        try {
          if (Modifier.isPublic(method.getModifiers())) {
            String name = method.getName();
            String key = "";
            if (name.startsWith("get")) {
              if ("getClass".equals(name) || "getDeclaringClass".equals(name)) {
                key = "";
              } else {
                key = name.substring(3);
              }
            } else if (name.startsWith("is")) {
              key = name.substring(2);
            }
            if (key.length() > 0
                && Character.isUpperCase(key.charAt(0))
                && method.getParameterTypes().length == 0) {
              if (key.length() == 1) {
                key = key.toLowerCase();
              } else if (!Character.isUpperCase(key.charAt(1))) {
                key = key.substring(0, 1).toLowerCase() + key.substring(1);
              }
              methodInfos.add(new MethodInfo(key, method));
            }
          }
        } catch (Exception ignored) {
        }
      }

      METHOD_MAP.putIfAbsent(clazz, methodInfos);
    }

    return methodInfos;
  }
コード例 #2
0
 private static boolean isJSONArray(Class<?> clazz) {
   if (clazz.isArray()) {
     return true;
   }
   if (Collection.class.isAssignableFrom(clazz)) {
     return true;
   }
   return false;
 }