title: Ignoring incoming json elements in jax-rs
body: <p>I'm wondering where to put the <code>@JsonIgnoreProperties(ignoreUnknown = true)</code> in a Java REST API. I have the following class:</p>
  
  <pre><code>import org.codehaus.jackson.annotate.JsonIgnoreProperties;
  import org.codehaus.jackson.map.ObjectMapper;
  
  @JsonIgnoreProperties(ignoreUnknown = true)
  public class QueuePayload {
      private String message;
      private String id;
  
      public String getId() {
          return this.id;
      }
  
      public String getMessage() {
          return this.message;
      }
  
      public void setId(String id) {
          this.id = id;
      }
  
      public void setMessage(String message) {
          this.message = message;
      }
  
      public String serialize() throws JsonProcessingException {
          ObjectMapper mapper = new ObjectMapper();
          return mapper.writeValueAsString(this);
      }
  }
  </code></pre>
  
  <p>Which I use in a JAX-RS servlet like this:</p>
  
  <pre><code>import javax.jms.JMSException;
  import javax.naming.NamingException;
  import javax.ws.rs.Consumes;
  import javax.ws.rs.GET;
  import javax.ws.rs.POST;
  import javax.ws.rs.Path;
  import javax.ws.rs.PathParam;
  import javax.ws.rs.Produces;
  import javax.ws.rs.QueryParam;
  import javax.ws.rs.core.MediaType;
  import javax.ws.rs.core.Response;
  import javax.ws.rs.core.Response.Status;
  
  
  
  @Path("/v1")
  @Produces(MediaType.APPLICATION_JSON)
  public class ServiceApiV1 {
  
      @GET
      public Response getApiRoot() {
          String result = "{\"notice\" : \"It is alive!\"}";
          return Response.status(Status.OK).entity(result).build();
      }
  
      @POST
      @Path("/update")
      @Consumes(MediaType.APPLICATION_JSON)
      public Response update(UpdatePayload message) {
          return Response.status(Status.OK).entity(message).build();
      }
  }
  </code></pre>
  
  <p>When I post <code>{ "message" : "Test", "id" : "one" }</code> it works like a charm, but when I post <code>{ "message" : "Test", "id" : "one", "sneaked" : "in" }</code> I get:</p>
  
  <pre>
  SRVE0315E: An exception occurred:
  com.ibm.ws.webcontainer.webapp.WebAppErrorReport:
     javax.servlet.ServletException:
       org.codehaus.jackson.map.exc.UnrecognizedPropertyException:
       Unrecognized field "sneaked";
       (Class test.QueuePayload), not marked as ignorable
   at [Source: com.ibm.ws.webcontainer.srt.SRTInputStream@b7328421&#59; line: 1, column: 7] &#40;through reference chain: test.QueuePayload["sneaked"]&#41;
  </pre>
  
  <p>I though <code>@JsonIgnoreProperties(ignoreUnknown = true)</code> was designed exactly for this use case. I also tried without the property in the servlet and the various permutations. I checked <a href="https://stackoverflow.com/questions/20986995/jsonignoreproperties-not-working">this question</a> and made sure to have imported the same API version in both classes.</p>
  
  <p>What do I miss?</p>
  
  <p><strong>Update</strong></p>
  
  <p>Change the imported classed to codehouse (see above) and ran this test):</p>
  
  <pre><code>public static void main(String[] args) throws IOException {
      // TODO Auto-generated method stub
      QueuePayload qp = new QueuePayload();
      qp.setPayload("PayLoad");
      qp.setQueueId("ID-of-Q");
      qp.setStatus("Some Status");
      System.out.println(qp.serialize());
  
      ObjectMapper om = new ObjectMapper();
      QueuePayload qp2 = om.readValue("{\"payload\":\"PayLoad\",\"queueId\":\"ID-of-Q\",\"newstatus\":\"New Status\"}",
                  QueuePayload.class);
      System.out.println(qp2.serialize());
  }
  </code></pre>
  
  <p>That worked. The servlet doesn't</p>