title: Design pattern to use for Null check through Reflection
body: <p>What we are doing - Annotation driven null and empty values check for Object.</p>
  
  <p>How we are doing - Creating one annotation and putting that annotation on the variable declaration.</p>
  
  <blockquote>
    <p>I am not sure what design pattern i need to use to make it work best</p>
  </blockquote>
  
  <p>. Please suggest.</p>
  
  <p>Annotation class -</p>
  
  <pre><code>@Target(ElementType.FIELD)
  
  
  @Retention(RetentionPolicy.RUNTIME)
  
  public @interface Test {
  
  
  /**
   * Message.
   *
   * @return the string
   */
  public String message();
  
  }
  </code></pre>
  
  <p>How we are declaring variable -</p>
  
  <pre><code>@Test(message="five message")
  private String five;
  </code></pre>
  
  <p>How i am calling annotation processor - </p>
  
  <pre><code>    Class&lt;?&gt; annotationClass = annotationTestinClass.getClass();
      Field[] decalaredFieldsArray = annotationClass.getDeclaredFields();
      List&lt;String&gt; lstString = new ArrayList&lt;&gt;();
      parseFields(decalaredFieldsArray,annotationTestinClass,lstString);
  </code></pre>
  
  <p>How i am processing object -</p>
  
  <pre><code>    public static List&lt;String&gt; parseFields(Field[] decalaredFieldsArray,Object obj,List&lt;String&gt; lstString){
  
      Arrays.stream(decalaredFieldsArray).forEach(field -&gt;{
          field.setAccessible(true);
          Test test = field.getDeclaredAnnotation(Test.class);
          if(field.getType().isPrimitive() || field.getType().getName().equals("java.lang.String")){
              if(field.isAnnotationPresent(Test.class)){
                  try {
                      System.out.println("field value is :"+field.get(obj));
                      System.out.println("field Name is :"+field.getName());
                      if(field.get(obj)== null || !StringUtils.isNoneBlank(field.get(obj).toString())){
                          lstString.add(test.message());
                      }
  
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
              }
          }else{
              Field[] objectFields =null;
              Object objValue = null;
              try {
                  if(field.isAnnotationPresent(Test.class)){
                      objValue = field.get(obj);
                      if(objValue!=null){
                          objectFields = objValue.getClass().getDeclaredFields();
                          parseFields(objectFields, objValue, lstString);
                      }else{
                          System.out.println("Object value is -"+field.get(obj));
                          System.out.println("Messsage value is -"+test.message());
                          lstString.add(test.message());
                      }
                  }
  
              } catch (Exception e1) {
                  e1.printStackTrace();
              }
  
          }
  
      });
      return lstString;
  }
  </code></pre>
  
  <p>Here Test.Class is repersenting my Test annotation.</p>