Accessing all fields from a POJO class using Java Reflection -
i have question regarding java reflection. trying fields (includes public , private fields) of particular class.
public class address extends basemodel { /** * */ private static final long serialversionuid = 1l; private string streetaddress; private string city; private string state; private string postalcode; private string country; // references............ private candidate candidate; private trainingbatch trainingbatch; private contactinformation contactinformation; // getters , setters } i trying these fields using java reflection. if observe pojo class using other classes references (like candidate, trainingbatch, contactiformation). below code accessing fields using java reflection.
public class reflection { public static void main(string[] args) throws classnotfoundexception { string name = address.class.getname(); system.out.println(name); class cls = class.forname(name); // field[] fields = cls.getfields(); field[] fields = cls.getdeclaredfields(); (field field : fields) { if(cls.isassignablefrom(field.gettype())){ system.out.println(field.getname() + "\t" + field.gettype()); } } } } so here when execute getting fields in pojo classes. don't want referenced fields , "serialversionuid" field. how can avoid these fields using java reflection. there way in java reflection. please me on this.
thanks in advance... :)
Comments
Post a Comment