2

I have requirement where in I will be given an object and I have to prepare a list of all the attributes in that object. The object can be a composite object. The idea is to get the list of all the attributes of type String, Integer, boolean and Date. There is a way to use reflection mechanism and doing this recursively. However, this can become quite complex. So I was just wondering, if there is any third party library that I can use.

Gaurav
  • 1,549
  • 2
  • 15
  • 31
  • attribute mean class property right ? – erimerturk Nov 25 '11 at 09:23
  • What is a 'class property'? Classes have attributes in the class file spec (like what tells the compiler about generic parameters), do you mean those or javabeans getter/setter style properties? – Ramon Nov 25 '11 at 09:29
  • See this similar question: http://stackoverflow.com/questions/1042798/retrieving-the-inherited-attribute-names-values-using-java-reflection – Pino May 15 '12 at 10:19

1 Answers1

0

Try looking at Apache BeanUtils. In particular PropertyUtils.getPropertyDescriptors(). Caveat, this only works for fields with getters and setters.

You'd then have to call this recursively for each property descriptor you find in the parent class.

Matthew Farwell
  • 60,889
  • 18
  • 128
  • 171