title: Jersey/Jackson: how to catch json mapping exception?
body: <p>I would like to catch json mapping exception in my restful service in case input json is not valid. </p>
  
  <p>It throws <code>org.codehaus.jackson.map.JsonMappingException</code>, but I don't how to or where to catch this exception. I want to catch this exception and send back appropriate error response.</p>
  
  <pre><code>@JsonInclude(JsonInclude.Include.NON_NULL)
  @Generated("org.jsonschema2pojo")
  @JsonPropertyOrder({
          "name",
          "id"
  })
  public class Customer {
      @JsonProperty("name")
      private String name;
  
      @JsonProperty("id")
      private String id;
       &lt;setter/getter code&gt;
  }
  
  public class MyService {
     @POST
      @Consumes(MediaType.APPLICATION_JSON)
      public final Response createCustomer(@Context HttpHeaders headers,
              Customer customer) {
          System.out.println("Customer data: " + customer.toString());
          return Response.ok("customer created").build();
      }
  }
  </code></pre>
  
  <p>Everything works fine, but if json body is not well formed then it throws <code>JsonMappingException</code> exception. I want to catch this exception.</p>