Bean Property Access and Annotations

Are there any java libraries that allow me to use BeanUtils as access to the properties of bean.prop1.prop2 , while allowing access to annotations on the getter / field itself?

For example, I have a bean class that looks like this:

 public class Child { @SomeCustomAnnotation private String name; //standard bean getter setters } public class Parent { private Child child; //standard bean getter setters } 

And I would like to get not only the value of the property I'm looking for, but also any annotations annotated in this field that returns the value:

 String childsName = SomeLibrary.getValue(parent, "child.name"); Annotation[] annotationsOnChildsName = SomeLibrary.getAnnotations(parent, "child.name"); 

Are there any libraries that allow both functions? I can use Commons BeanUtils to get pure property access for values ​​and Plain Reflection to get property annotations, but there seems to be no way to combine both.

+4
source share
1 answer

If I'm missing something, you can just flip the Field class

 Field f = Parent.class.getField("name"); Object value = f.get(parent); f.getAnnotations(); 
+3
source

Source: https://habr.com/ru/post/1379318/


All Articles