diff --git a/README.md b/README.md index 56ee46e..498ef09 100644 --- a/README.md +++ b/README.md @@ -121,13 +121,13 @@ curl -X POST -H "Content-type: application/json" -d '{ app.tozzi jpa-search-helper - 3.3.1 + 3.3.2 ``` #### Gradle ``` -implementation 'app.tozzi:jpa-search-helper:3.3.1 +implementation 'app.tozzi:jpa-search-helper:3.3.2 ``` ## Queries - Usage diff --git a/build.gradle b/build.gradle index 8de2a36..018eab3 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ plugins { } group = 'app.tozzi' -version = '3.3.1' +version = '3.3.2' compileJava { sourceCompatibility = JavaVersion.VERSION_17 @@ -65,7 +65,7 @@ publishing { maven(MavenPublication) { group = 'app.tozzi' artifactId = 'jpa-search-helper' - version = "3.3.1" + version = "3.3.2" from components.java pom { name = 'JPA Search Helper' diff --git a/src/main/java/app/tozzi/util/ReflectionUtils.java b/src/main/java/app/tozzi/util/ReflectionUtils.java index dd116e7..003cbed 100644 --- a/src/main/java/app/tozzi/util/ReflectionUtils.java +++ b/src/main/java/app/tozzi/util/ReflectionUtils.java @@ -6,8 +6,8 @@ import app.tozzi.annotation.Searchable; import app.tozzi.exception.JPASearchException; import jakarta.persistence.*; +import org.apache.commons.lang3.reflect.FieldUtils; import org.apache.commons.lang3.tuple.Pair; -import org.springframework.beans.BeanUtils; import java.lang.annotation.Annotation; import java.lang.reflect.Field; @@ -73,7 +73,7 @@ public static Map> getAllProjectableFields(Clas private static void getFields(final StringBuilder root, Class beanClass, Class annotationClass, Class nestedAnnotationClass, Map> res, boolean evaluateNested) { - Stream.of(BeanUtils.getPropertyDescriptors(beanClass)).flatMap(pd -> Stream.of(pd.getReadMethod().getDeclaringClass().getDeclaredFields())) + Stream.of(FieldUtils.getAllFields(beanClass)) .forEach(f -> { if (f.isAnnotationPresent(annotationClass)) { diff --git a/src/test/java/app/tozzi/model/ModelA.java b/src/test/java/app/tozzi/model/ModelA.java new file mode 100644 index 0000000..9cb11d2 --- /dev/null +++ b/src/test/java/app/tozzi/model/ModelA.java @@ -0,0 +1,15 @@ +package app.tozzi.model; + +import app.tozzi.annotation.Searchable; +import lombok.Data; + +@Data +public class ModelA { + + @Searchable + private String modelAID; + + @Searchable + private String modelAField; + +} diff --git a/src/test/java/app/tozzi/model/ModelB.java b/src/test/java/app/tozzi/model/ModelB.java new file mode 100644 index 0000000..ec53004 --- /dev/null +++ b/src/test/java/app/tozzi/model/ModelB.java @@ -0,0 +1,17 @@ +package app.tozzi.model; + +import app.tozzi.annotation.Searchable; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@Data +@EqualsAndHashCode(callSuper = true) +public class ModelB extends ModelA { + + @Searchable + private String modelBID; + + @Searchable + private String modelBField; + +} diff --git a/src/test/java/app/tozzi/util/ReflectionUtilsTest.java b/src/test/java/app/tozzi/util/ReflectionUtilsTest.java index a099b03..37986d9 100644 --- a/src/test/java/app/tozzi/util/ReflectionUtilsTest.java +++ b/src/test/java/app/tozzi/util/ReflectionUtilsTest.java @@ -1,9 +1,6 @@ package app.tozzi.util; -import app.tozzi.model.JPASearchOperatorFilter; -import app.tozzi.model.JPASearchType; -import app.tozzi.model.MyModel; -import app.tozzi.model.RecursiveModel; +import app.tozzi.model.*; import org.junit.jupiter.api.Test; import java.math.BigDecimal; @@ -73,4 +70,15 @@ public void recursiveModelTest() { assertTrue(map.containsKey("predecessor.name")); assertEquals(30, map.size()); } + + @Test + public void inheritanceTest() { + var map = ReflectionUtils.getAllSearchableFields(ModelB.class); + assertNotNull(map); + assertTrue(map.containsKey("modelBID")); + assertTrue(map.containsKey("modelBField")); + assertTrue(map.containsKey("modelAID")); + assertTrue(map.containsKey("modelAField")); + assertEquals(4, map.size()); + } }