Repository: searchbox-io/Jest (java)

Issue:
@JestId annotation not found in super class
I would like to suggest an enhancement.
We have a family of documents which share a number of fields and we wanted to separate out the common fields into a super class from which all document types inherit. Particularly the id-field is common to all document types.
The code which looks for the @JestId annotation does not seem to traverse the class hierarchy up in an attempt to find the annotation? 
Btw, spring does it so why don't we?


Pull request description:
Look for meta fields also in superclasses
Fixes #181

Patch:
diff --git a/jest-common/src/main/java/io/searchbox/client/JestResult.java b/jest-common/src/main/java/io/searchbox/client/JestResult.java
index 83e4b79a..89b5edd8 100644
--- a/jest-common/src/main/java/io/searchbox/client/JestResult.java
+++ b/jest-common/src/main/java/io/searchbox/client/JestResult.java
@@ -263,18 +263,24 @@ public class JestResult {
             obj = gson.fromJson(json, type);
 
             // Check if JestId is visible
-            Field[] fields = type.getDeclaredFields();
+            Class clazz = type;
             int knownMetadataFieldsCount = META_FIELDS.size();
             int foundFieldsCount = 0;
-            for (Field field : fields) {
-                if (foundFieldsCount == knownMetadataFieldsCount) {
-                    break;
-                }
-                for (MetaField metaField : META_FIELDS) {
-                    if (field.isAnnotationPresent(metaField.annotationClass) && setAnnotatedField(obj, source, field, metaField.internalFieldName)) {
-                        foundFieldsCount++;
+            boolean allFieldsFound = false;
+            while (clazz != null && !allFieldsFound) {
+                Field[] fields = clazz.getDeclaredFields();
+                for (Field field : fields) {
+                    if (foundFieldsCount == knownMetadataFieldsCount) {
+                        allFieldsFound = true;
+                        break;
+                    }
+                    for (MetaField metaField : META_FIELDS) {
+                        if (field.isAnnotationPresent(metaField.annotationClass) && setAnnotatedField(obj, source, field, metaField.internalFieldName)) {
+                            foundFieldsCount++;
+                        }
                     }
                 }
+                clazz = clazz.getSuperclass();
             }
 
         } catch (Exception e) {


Test patch:
diff --git a/jest-common/src/test/java/io/searchbox/client/JestResultTest.java b/jest-common/src/test/java/io/searchbox/client/JestResultTest.java
index b951d764..a5757cf8 100644
--- a/jest-common/src/test/java/io/searchbox/client/JestResultTest.java
+++ b/jest-common/src/test/java/io/searchbox/client/JestResultTest.java
@@ -551,12 +551,11 @@ public class JestResultTest {
         }
     }
 
-    class Comment {
+    abstract class Base {
+
         @JestId
         Long someIdName;
 
-        String message;
-
         public Long getSomeIdName() {
             return someIdName;
         }
@@ -564,6 +563,10 @@ public class JestResultTest {
         public void setSomeIdName(Long someIdName) {
             this.someIdName = someIdName;
         }
+    }
+
+    class Comment extends Base {
+        String message;
 
         public String getMessage() {
             return message;