title: Accessing all fields from a POJO class using Java Reflection
body: <p>I have a question regarding java reflection. I am trying to get all the fields (Includes Public and Private Fields) of a particular class.</p>
  
  <pre><code>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 And Setters
  
  }
  </code></pre>
  
  <p>I am trying to get all these fields using Java Reflection. But if you observe my POJO class I am using other classes references (Like Candidate, TrainingBatch, ContactIformation). Below is the code I am accessing fields using Java Reflection.</p>
  
  <pre><code>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();
      for (Field field : fields) {
          if(cls.isAssignableFrom(field.getType())){
          System.out.println(field.getName() + "\t" + field.getType());
          }
      }
  }
  }
  </code></pre>
  
  <p>So here when I execute this I am getting all the fields which are in my POJO classes. But I don't want the referenced fields and as well as "serialVersionUID" field. So how can I avoid these fields using Java reflection. Is there any way in Java Reflection. Please help me on this.</p>
  
  <p>Thanks in advance... :)</p>