title: Best way to check if an object is null to prepare for mapping
body: <p>I’m trying to map an object to another and I’m having trouble deciding what’s the best practice to check if the object from where I want to map is null</p>
  
  <p>1 - </p>
  
  <pre><code>public DTOIntIdentityDocument mapIdentityDocument(Identitydocument in) {
          if (in == null) {
              return null;
          } else {
              DTOIntIdentityDocument out = new DTOIntIdentityDocument();
              out.setDocumentType(this.mapDocumentTypeÇ(in.getDocumenttype()));
              out.setDocumentNumber(in.getDocumentnumber());
              return out;
          }
      }
  </code></pre>
  
  <p>2 - </p>
  
  <pre><code>public DTOIntIdentityDocument mapIdentityDocument(Identitydocument in) {
          DTOIntIdentityDocument out = null;
  
          if (in != null) {
              out = new DTOIntIdentityDocument();
              out.setDocumentType(this.mapDocumentTypeÇ(in.getDocumenttype()));
              out.setDocumentNumber(in.getDocumentnumber());
          }
  
          return out;
      }
  </code></pre>
  
  <p>¿Any ideas on what's the best practice to do this?</p>