title: How to conditionally exclude property from a json response
body: <p>I have a class pojo used to return a response to an API call in the rest controller</p>
  <pre><code>EmployeeResponse response = validationService.validate(request);
  return new ResponseEntity&lt;&gt;(response, HttpStatus.OK);
  </code></pre>
  <p>However now we want to feature flag the controller class so that if a configuration property is not set, the response will not include a property.  How can we do that?</p>
  <pre><code>public class EmployeeResponse {
      private String firstName;
      private String lastName
      private String address;   // don't want to include this if boolean flag is not set
  }
  </code></pre>
  <p>EDIT:  adding the controller code here to show that an object is returned without being serialized so I don't see how to fit objectMapper into that</p>
  <pre><code>@RestController
  public class EmployeeController {
  
      @PostMapping(value = &quot;/validate&quot;, produces = MediaType.APPLICATION_JSON_VALUE)
      public ResponseEntity&lt;EmployeeResponse&gt; get(final @RequestBody EmployeeRequest employeeRequest) {
  
          MasterSubResponse response = validationService.validate(employeeRequest);
          return new ResponseEntity&lt;&gt;(response, HttpStatus.OK);
      }
  
  }
  </code></pre>