title: Error 415 Unsupported Media Type: POST not reaching REST if JSON, but it does if XML
body: <p>I am actually new to REST WS but really I don't get this <code>415 Unsupported Media Type</code>. </p>
  
  <p>I am testing my REST with Poster on Firefox and the <code>GET</code> works fine for me, also the <code>POST</code> (when it's a <code>application/xml</code>) but when I try <code>application/json</code> it doesn't not reach the WS at all, the server rejects it.</p>
  
  <p>This is my URL: http:// localhost:8081/RestDemo/services/customers/add</p>
  
  <p>This is <code>JSON</code> I'm sending: <code>{"name": "test1", "address" :"test2"}</code></p>
  
  <p>This is <code>XML</code> I'm sending:</p>
  
  <pre><code>&lt;customer&gt;
      &lt;name&gt;test1&lt;/name&gt;
      &lt;address&gt;test2&lt;/address&gt;
  &lt;/customer&gt;
  </code></pre>
  
  <p>and this is my Resource class:</p>
  
  <pre><code>@Produces("application/xml")
  @Path("customers")
  @Singleton
  @XmlRootElement(name = "customers")
  public class CustomerResource {
  
      private TreeMap&lt;Integer, Customer&gt; customerMap = new TreeMap&lt;Integer, Customer&gt;();
  
      public  CustomerResource() {
          // hardcode a single customer into the database for demonstration
          // purposes
          Customer customer = new Customer();
          customer.setName("Harold Abernathy");
          customer.setAddress("Sheffield, UK");
          addCustomer(customer);
      }
  
      @GET
      @XmlElement(name = "customer")
      public List&lt;Customer&gt; getCustomers() {
          List&lt;Customer&gt; customers = new ArrayList&lt;Customer&gt;();
          customers.addAll(customerMap.values());
          return customers;
      }
  
      @GET
      @Path("/{id}")
      @Produces("application/json")
      public String getCustomer(@PathParam("id") int cId) {
          Customer customer = customerMap.get(cId); 
          return  "{\"name\": \" " + customer.getName() + " \", \"address\": \"" + customer.getAddress() + "\"}";
  
      }
  
      @POST
      @Path("/add")
      @Produces(MediaType.APPLICATION_JSON)
      @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
      public String addCustomer(Customer customer) {
           //insert 
           int id = customerMap.size();
           customer.setId(id);
           customerMap.put(id, customer);
           //get inserted
           Customer result = customerMap.get(id);
  
           return  "{\"id\": \" " + result.getId() + " \", \"name\": \" " + result.getName() + " \", \"address\": \"" + result.getAddress() + "\"}";
      }
  
  }
  </code></pre>
  
  <p><strong>EDIT 1:</strong></p>
  
  <p>This is my Customer class:</p>
  
  <pre><code>@XmlRootElement 
  public class Customer implements Serializable {
  
      private int id;
      private String name;
      private String address;
  
      public Customer() {
      }
  
      public int getId() {
          return id;
      }
  
      public void setId(int id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public String getAddress() {
          return address;
      }
  
      public void setAddress(String address) {
          this.address = address;
      }
  
  }
  </code></pre>