I jave a simple Java bean with 4 attributes, getter/setter, and some overided methods like toString, equals and hashCode.
Above every Attribute is a custom Annotation:
import java.lang.annotation.*;
import java.lang.annotation.RetentionPolicy;
@Target(ElementType.FIELD)
@Retention( RetentionPolicy.RUNTIME )
public @interface DAOProperty {
String name();
String type();
boolean identifier() default false;
}
/** The id. */
@DAOProperty(name = "id", type = "long", identifier = true)
private long id;
If I pass the bean.class to another method
generateEntity(User.class);
…
private static MEntity generateEntity(Class<?> bean) {...}
and debug it, it seems to bee empty, except for the class name. All arrays like methods, annotations and fields are of zero size.
Where did I go wrong?
Use
beanClass.getDeclaredFields()instead ofgetFields(). Then iterate the array and for eachFieldcallgetAnnotations()getFields()(and the similar methods) return only the public members.Anyway, why don’t you use JPA, instead of creating your own annotations and annotation processors?