title: In REST / Java, what should I return if my object is null?
body: <p>I have a simple POJO that I annotated with REST annotations as follows:</p>
  <pre><code>@GET
  @Path(&quot;/domains/{domainid}&quot;)
  @Override
  public Domain getDomain(@PathParam(&quot;domainid&quot;) UUID domainID) throws Exception {
      logger.info(&quot;Retrieving domain &quot;+ domainID);
      Domain d = null;
      try {
          d = MyClient.getDomains().get(domainID.toString());
          logger.debug(&quot;Returning &quot;+d.getName());
      } catch (Exception e) {
          logger.error(&quot;Could not retrieve domain&quot;, e);
      }
      return d;
  }
  </code></pre>
  <p>Note that the log statement including <code>d.getName()</code> can actually throw an NPE which is then caught and logged. That's not pretty but it's also not the point here.</p>
  <p>Ultimately whether <code>d</code> has a value or not, I return it.</p>
  <p>In the case of a <code>null</code> value, my client receives an HTTP 204 status code. This is what <code>wget</code> displays: <code>HTTP request sent, awaiting response... 204 No Content</code></p>
  <p>Oddly enough, my browsers don't budge an inch. They still display the previous page (I suppose it makes sense to stay put when no content is received). I would have expected a blank page.</p>
  <p>Three questions:</p>
  <ul>
  <li>is HTTP 204 the right response to be returned?</li>
  <li>how can I control that via annotations? Via other configuration?</li>
  <li>what is the standard REST best practice regarding null objects?</li>
  </ul>
  <p>Thanks</p>
  <h3>EDIT</h3>
  <p>There is a great question on the very same topic here: <a href="https://stackoverflow.com/questions/26845631/is-it-correct-to-return-404-when-a-rest-resource-is-not-found/26845991#26845991">Is it correct to return 404 when a REST resource is not found?</a></p>