title: How @JsonInclude(Include.NON_NULL) works In Spring Boot
body: <p>I am trying to understand what is the reason of existence @JsonInclude to use it in my DTOs. Let's look at this simple example:</p>
  
  <p><strong>A Code:</strong></p>
  
  <pre><code>class DemoApplication {
      static void main(String[] args) {
          SpringApplication.run DemoApplication, args
      }
      @PostMapping("/")
      String greet(@RequestBody Greeting greeting) {
          return "Hello ${greeting.name}, with email ${greeting.email}"
      }
  }
  
  @JsonInclude(JsonInclude.Include.NON_NULL)
  class Greeting {
    String name
    String email
  }
  </code></pre>
  
  <p><strong>B Code:</strong></p>
  
  <pre><code>class DemoApplication {
      static void main(String[] args) {
          SpringApplication.run DemoApplication, args
      }
      @PostMapping("/")
      String greet(@RequestBody Greeting greeting) {
          return "Hello ${greeting.name}, with email ${greeting.email}"
      }
  }
  
  class Greeting {
    String name
    String email
  }
  </code></pre>
  
  <p>The only difference between the <strong>A code</strong> and the <strong>B code</strong> is that in the <strong>B code</strong> the greeting class does not use the <strong>@JsonInclude</strong> annotation.</p>
  
  <p>But if I do some simple CURL requests to that endpoint (<strong>A code</strong> and <strong>B code</strong>):</p>
  
  <pre><code>~ curl -H "Content-Type: application/json" -X POST localhost:8080
  {"timestamp":"2018-04-22T21:18:39.849+0000","status":400,"error":"Bad Request","message":"Required request body is missing: public java.lang.String com.example.demo.DemoApplication.greet(com.example.demo.Greeting)","path":"/"}
  ~ curl -H "Content-Type: application/json" -X POST localhost:8080  -d '{}'
  Hello null, with email null                                                                     
  ~ curl -H "Content-Type: application/json" -X POST localhost:8080  -d '{"name": "AlejoDev"}'
  Hello AlejoDev, with email null                                                                    
  ~ curl -H "Content-Type: application/json" -X POST localhost:8080  -d '{"name": "AlejoDev", "email":"info@alejodev.com"}'
  Hello AlejoDev, with email info@alejodev.com
  </code></pre>
  
  <p>Get the same behavior, then what is the utility of using <strong>@JsonInclude</strong> annotation?</p>
  
  <p>For example, I expected that in <strong>A code</strong> when I sent a request with only one field, like this:</p>
  
  <pre><code>~ curl -H "Content-Type: application/json" -X POST localhost:8080  -d '{"name": "AlejoDev"}'
  </code></pre>
  
  <p>the <strong>Greeting object</strong> <em>became an object with only one field</em>, and not an object with two fields. one full and one empty.</p>