[LIB-8] Modify URL entity annotation functionality
authorgotty <gotty@fb0bcced-7025-49ed-a12f-f98bce993226>
Thu, 14 Nov 2019 22:00:43 +0000 (22:00 +0000)
committergotty <gotty@fb0bcced-7025-49ed-a12f-f98bce993226>
Thu, 14 Nov 2019 22:00:43 +0000 (22:00 +0000)
git-svn-id: https://svn.hedgecode.org/lib/snooker-score-api/trunk@177 fb0bcced-7025-49ed-a12f-f98bce993226

src/main/java/org/hedgecode/snooker/json/JsonURLEntity.java

index 9798671..f49f399 100644 (file)
@@ -94,7 +94,7 @@ public abstract class JsonURLEntity implements URLEntity {
                             field.getName(),
                             (String) field.get(this)
                     );
-                } catch (Exception ignored) {
+                } catch (ReflectiveOperationException ignored) {
                 }
             }
         }
@@ -106,18 +106,16 @@ public abstract class JsonURLEntity implements URLEntity {
             String fieldName
     ) {
         String result = null;
-        Class<?> clazz = getClass();
-        for (Field field : clazz.getDeclaredFields()) {
+        try {
+            Class<?> clazz = getClass();
+            Field field = clazz.getDeclaredField(fieldName);
             if (field.isAnnotationPresent(annotationClass)
-                    && field.getName().equals(fieldName)
                     && field.getType().equals(String.class))
             {
                 field.setAccessible(true);
-                try {
-                    result = (String) field.get(this);
-                } catch (Exception ignored) {
-                }
+                result = (String) field.get(this);
             }
+        } catch (ReflectiveOperationException ignored) {
         }
         return result;
     }
@@ -127,17 +125,17 @@ public abstract class JsonURLEntity implements URLEntity {
     ) {
         Map<String, String> result = new HashMap<>();
         Class<?> clazz = getClass();
-        for (Method method : clazz.getMethods()) {
+        for (Method method : clazz.getDeclaredMethods()) {
             if (method.isAnnotationPresent(annotationClass)
-                    && method.getReturnType().equals(String.class)
-                    && method.getParameterCount() == 0)
+                    && method.getParameterCount() == 0
+                    && method.getReturnType().equals(String.class))
             {
                 try {
                     result.put(
                             method.getName(),
                             (String) method.invoke(this)
                     );
-                } catch (Exception ignored) {
+                } catch (ReflectiveOperationException ignored) {
                 }
             }
         }
@@ -149,18 +147,15 @@ public abstract class JsonURLEntity implements URLEntity {
             String methodName
     ) {
         String result = null;
-        Class<?> clazz = getClass();
-        for (Method method : clazz.getMethods()) {
+        try {
+            Class<?> clazz = getClass();
+            Method method = clazz.getDeclaredMethod(methodName);
             if (method.isAnnotationPresent(annotationClass)
-                    && method.getName().equals(methodName)
-                    && method.getReturnType().equals(String.class)
-                    && method.getParameterCount() == 0)
+                    && method.getReturnType().equals(String.class))
             {
-                try {
-                    result = (String) method.invoke(this);
-                } catch (Exception ignored) {
-                }
+                result = (String) method.invoke(this);
             }
+        } catch (ReflectiveOperationException ignored) {
         }
         return result;
     }