Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use <a href="http://docs.oracle.com/javase/6/docs/api/java/lang/reflect/Field.html#getType%28%29" rel="nofollow">getType</a> method to determine the type of fields and then use only required fields. For this particualr scenario you can check if the filed if type <code>Date</code> or <code>String</code>. </p> <hr> <p><strong>EDIT :</strong> </p> <p><strong>Using annotation + Reflection</strong> </p> <p><strong>Step 1:</strong> Define your custom annotation. Here <code>DesiredField</code> is our custom annotation </p> <pre><code>@Target(value = ElementType.FIELD) @Retention(value = RetentionPolicy.RUNTIME) public @interface DesiredField { } </code></pre> <p><strong>Step 2:</strong> Annotate appropriate fields with <code>DesiredField</code>, you should annotate <code>dateOfBirth</code> and <code>aadhaarNumber</code> like </p> <pre><code>public class Person extends BaseModel { @DesiredField private Date dateOfBirth; @DesiredField private String aadhaarNumber; private Set&lt;EducationQualification&gt; educationQualifications; // Rest of the fields and methods } </code></pre> <p><strong>Step 3:</strong> Use reflection to find annotated fields </p> <pre><code> Person person = new Person(); Field[] fields = person.getClass().getFields(); for(Field field : fields){ DesiredField annotation = field.getAnnotation(DesiredField.class); if( annotation != null ){ // This is desired field now do what you want } } </code></pre> <p>This might help : <a href="http://www.vogella.com/articles/JavaAnnotations/article.html" rel="nofollow">http://www.vogella.com/articles/JavaAnnotations/article.html</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload