vendredi 12 octobre 2018

Get all Fields of class including the ones which are other classes

Based on the question Get all Fields of class hierarchy I want to ask the following using -as I suppose- reflection. Lets suppose I have the following Class

package com.foo.bar

public class Employee{ 

    private String firstName; 

    private String id; 

    private Address address; 

// Getters and Setters follow

}

and the Class Address is

package com.foo.bar

public class Address{ 

    private String street; 

    private String streetNum; 

// Getters and Setters follow

}

I want to populate a list with all fields from all classes originating from Employee in the form

  • Employee.firstName
  • Employee.id
  • Employee.Address.street
  • Employee.Address.streetNum

All the classes I am interested in are either in the same package as Employee class ex com.foo.bar or in specific packages that I am already aware of.

My original thinking is to somehow get all the fields, get the packages from the class of the fields and somehow drill down in multiple levels to get the information I need.

Any help is greatly appreciated.

Thanks

ps. I am using JDK 7





Aucun commentaire:

Enregistrer un commentaire