0

I have a bean with annotated getters and fields:

public class CaseSimpleObjGetter {
    private int a;

    @Hashed
    private int b;

    private int c;

    CaseSimpleObjGetter(int a, int b, int c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }

    @Hashed
    public int getA() {
        return a;
    }

    protected int getB() {
        return b;
    }

    protected int getC() {
        return c;
    }
}

I want to implement an extractor that will extract all accessible fields from similar objects.
Especially, I want to access annotation information.
I wonder, what is the best way to implement that extractor?
In this example I would like to extract names and values for (a, b, c) and know which are annotated with @Hashed annotation.

I was using previously BeanWrapperImpl (from spring) and Introspector.
However, I couldn't find methods to access annotations from properties.
Are annotations in fact allowed in beans?

oneat
  • 10,778
  • 16
  • 52
  • 70
  • Basically, making the class a bean is based on XML configuration or Java annotations. – Marcin Rzepecki Dec 01 '20 at 12:50
  • 1
    From what I understand bean is just a convention with getters and private fields as in: https://stackoverflow.com/questions/3295496/what-is-a-javabean-exactly – oneat Dec 01 '20 at 12:58
  • Is this resolve your issue with acessing annotations of bean properties? https://stackoverflow.com/a/4454783/14056755 – Marcin Rzepecki Dec 01 '20 at 13:07
  • not sure if it handles getters – oneat Dec 01 '20 at 13:34
  • There seems not to be "out of the box" solutions at quick search. Also "best way" is opinion based but I think in this case the best is also the only way ie plain reflection that involves some mapping of fields and getters and so on. What I have in mind is possible with bean and only with bean convention. – pirho Dec 01 '20 at 17:57

0 Answers0