In common case you have private access for fields, so you CAN'T use getFields in reflection. Instead of this you should use getDeclaredFields
So, firstly, you should be aware if your Column annotation has the runtime retention:
@Retention(RetentionPolicy.RUNTIME)
@interface Column {
}
After that you can do something like this:
for (Field f: MyClass.class.getDeclaredFields()) {
Column column = f.getAnnotation(Column.class);
// ...
}
Obviously, you would like to do something with field - set new value using annotation value:
Column annotation = f.getAnnotation(Column.class);
if (annotation != null) {
new PropertyDescriptor(f.getName(), Column.class).getWriteMethod().invoke(
object,
myCoolProcessing(
annotation.value()
)
);
}
So, full code can be looked like this:
for (Field f : MyClass.class.getDeclaredFields()) {
Column annotation = f.getAnnotation(Column.class);
if (annotation != null)
new PropertyDescriptor(f.getName(), Column.class).getWriteMethod().invoke(
object,
myCoolProcessing(
annotation.value()
)
);
}