flybywire
flybywire

Reputation: 273582

Has the JavaBean spec been updated to reflect the existence of annotations

I thought this should be obvious but I can't find it.

Now that fields can have annotations, I thought this should be reflected in the JavaBean spec, but I can't find it.

What I mean:

JavaBean is a specification that allows you to treat objects in an uniform way by discovering their properties, and then reading and writing them.

As POJOs properties can now be annotated (as in Hibernate annotations for example), I expected annotations to be accessible using the JavaBean specification - in order to discover more metadata than just the type of the property.

Or must I resort to the trick of getting the getter method and find the metadata using plain reflection API?

Upvotes: 3

Views: 363

Answers (1)

John Meagher
John Meagher

Reputation: 24718

You can access the getter and setter methods through the PropertyDescriptor class in the Java Beans API. From getReadMethod() and getWriteMethod() the annotations on those methods are available. In the end it is a little bit of a mix between the Java Beans API and the Reflection API.

Upvotes: 5

Related Questions