title: Checking if object contains null values
body: <p>I want to write a method that checks if given object contains fields of null value. What I've written works fine BUT the problem occurs with primitive types.</p>
  
  <pre><code>public static &lt;T&gt; List&lt;String&gt; checkIfNullsInObject(T ob) {
  
          List&lt;String&gt; fieldsAsNull = new LinkedList&lt;&gt;();
  
          for (Field f : ob.getClass().getDeclaredFields()) {
              f.setAccessible(true);
              try {
                  if (Objects.isNull(f.get(ob))) {
                      fieldsAsNull.add(f.getName());
                  }
              } catch (Exception e) {
                  e.getMessage();
                  e.printStackTrace();
              }
          }
          return fieldsAsNull;
      }
  </code></pre>
  
  <p>so eg.</p>
  
  <p>class Dog:</p>
  
  <pre><code>public class Dog {
      private String name;
      private int age;
      private String owner;
  ///set get
  }
  </code></pre>
  
  <p>given Object : </p>
  
  <pre><code>Dog dog = new Dog();
          // dog.setAge(44);
          // dog.setName("Maniek");
          // dog.setOwner("AZE");
  </code></pre>
  
  <p>the method should return "age , name ,owner", but it only returns two last one. I know that int is set to 0, and therfore it is not considered as null because of beeing primitive type and not a refrence to null. </p>
  
  <p>The <strong>java doc</strong> about Field.get(Object o) method says : </p>
  
  <p><strong>Returns the value of the field represented by this Field, on the specified object. The value is automatically wrapped in an object if it has a primitive type.</strong> </p>
  
  <p>If it's wrapped to object I'd expect it to return null, not zero what am I missing here? Is it unwrapped once again somewhere in between?</p>
  
  <p>/////////////////////////////////////////////////////</p>
  
  <p>I knew that changing type to Wrapper class would do the job, but I'm not sure if changing another class because of adding another class is good practice therefore I've decided to do soemthing like this:</p>
  
  <pre><code>public static &lt;T&gt; void  checkIfNullsInObject(T ob) throws DataInputException {
          try {
              for (Field f : ob.getClass().getDeclaredFields()) {
                  f.setAccessible(true);
                  if (Objects.isNull(f.get(ob)) || checkForZeroPrimitives(ob, f)) 
                      throw new DataInputException("Can not update entity with field \"" 
                              + f.getName() + "\" set to: " + f.get(ob));
              }
          } catch (IllegalArgumentException |IllegalAccessException e) {
              e.getMessage();
              e.printStackTrace();
          }
  
      }
  
      private static &lt;T&gt; boolean checkForZeroPrimitives(T ob, Field field) throws IllegalArgumentException, IllegalAccessException {
          if (field.getType().getName().equals("int") &amp;&amp; field.getInt(ob) == 0)
              return true;
          if (field.getType().getName().equals("double") &amp;&amp; field.getDouble(ob) == 0.0)
              return true;
          if (field.getType().getName().equals("float") &amp;&amp; field.getFloat(ob) == 0)
              return true;
          if (field.getType().getName().equals("long") &amp;&amp; field.getLong(ob) == 0)
              return true;
          if (field.getType().getName().equals("short") &amp;&amp; field.getShort(ob) == 0)
              return true;
          if (field.getType().getName().equals("byte") &amp;&amp; field.getByte(ob) == 0)
              return true;
          if (field.getType().getName().equals("char") &amp;&amp; field.getChar(ob)=='\u0000')
              return true;
          return false;
              }
  </code></pre>
  
  <p>later on I intend to improve the -if ladder.</p>