Wiki

Clone wiki

bean-introspector / Home

About

Tool for introspection of beans. Can be used as a base for building other tools which rely on metadata dynamically linked to beans and it's properties.

Usage

Add it as maven dependency:

#!xml

<dependency>
  <groupId>org.bitbucket.brunneng.introspection</groupId>
  <artifactId>bean-introspector</artifactId>
  <version>1.0.7.2</version>
</dependency>

Let's print to console all fields of some bean Person with 2 properties: name and age.

#!java
Person person = new Person();
person.setName("Alex");
person.setAge(30);

Introspector introspector = new Introspector();
for (Property p : introspector.beanOfClass(Person.class).getProperties()) {
   System.out.println(p.getName() + ": " + p.getter().get(person));
}

// will print:
// name: Alex
// age: 30

Updated