title: How to ignore JSON field in response alone in java
body: <p>I want to exclude name and age from my response, but When I receive the JSON payload request I need name and age field - after my business logic, I want to send status and message as part of JSON response. name and age should exclude from that.  How can I achieve this in java?</p>
  
  <pre><code>public class Sample {
  
      private String name;
      private String age;
      private String status;
      private String message;
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public String getStatus() {
          return status;
      }
  
      public void setStatus(String status) {
          this.status = status;
      }
  
      public String getMessage() {
          return message;
      }
  
      public void setMessage(String message) {
          this.message = message;
      }
  
      public String getAge() {
          return age;
      }
  
      public void setAge(String age) {
          this.age = age;
      }
  }
  </code></pre>
  
  <p><strong>My Controller class:</strong></p>
  
  <pre><code>@PostMapping(path = "/testApp", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
  public ResponseEntity&lt;Object&gt; test(@RequestBody Sample sample) {
      Sample response = myService.calculate(sample);
      return new ResponseEntity&lt;Object&gt;(response, HttpStatus.OK);
  }
  </code></pre>
  
  <p><strong>My Request</strong></p>
  
  <pre><code>{
      "name": "Mark",
      "age": "48"
  }
  </code></pre>
  
  <p><strong>My Response</strong></p>
  
  <pre><code>{
      "status": "200",
      "message": "success"
  }
  </code></pre>