title: 415 unsupported media type in java jersey
body: <p>I am having problem with below code saying <strong>415 unsupported MEDIA type and The server refused this request because the request entity is in a format not supported</strong> for post method.</p>
  
  <p>Searched everywhere and did all the things yet no result.</p>
  
  <p>Help!!</p>
  
  <p>Below is the main code</p>
  
  <p><strong>ActivityResource.java</strong></p>
  
  <pre><code>@Path("activityresource")
  public class ActivityResource {
  
      private ActivityRepo activityRepo=new ActivityRepositoryStub();
  
      @POST
      @Path("postActivity")
      @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
      @Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
      public Activity createActivityParams(MultivaluedHashMap&lt;String, String&gt; formse){
          System.out.println(formse.getFirst("discription"));
          System.out.println(formse.getFirst("duration"));
  
          Activity activity=new Activity();
          activity.setDiscription(formse.getFirst("discription"));
          activity.setDuration(Integer.parseInt(formse.getFirst("duration")));
          activityRepo.create(activity);
  
          return activity;
      }
  }
  </code></pre>
  
  <h2>Activity.java</h2>
  
  <pre><code>package com.ws.model;
  
  import javax.xml.bind.annotation.XmlElement;
  import javax.xml.bind.annotation.XmlRootElement;
  
  @XmlRootElement
  public class Activity {
      private String id;
      private String discription;
      private int duration;
      private User user;
  
      public String getId() {
          return id;
      }
      public void setId(String id) {
          this.id = id;
      }
      @XmlElement(name="desc")
      public String getDiscription() {
          return discription;
      }
      public void setDiscription(String discription) {
          this.discription = discription;
      }
      public int getDuration() {
          return duration;
      }
      public void setDuration(int duration) {
          this.duration = duration;
      }
      public User getUser() {
          return user;
      }
      public void setUser(User user) {
          this.user = user;
      }
  }
  </code></pre>
  
  <h2>User.java</h2>
  
  <pre><code>package com.ws.model;
  
  import javax.xml.bind.annotation.XmlRootElement;
  
  @XmlRootElement
  public class User {
  
      private String id;
      private String name;
      public String getId() {
          return id;
      }
      public void setId(String id) {
          this.id = id;
      }
      public String getName() {
          return name;
      }
      public void setName(String name) {
          this.name = name;
      }
  }
  </code></pre>
  
  <p>POM.XML</p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;com.ws.app&lt;/groupId&gt;
      &lt;artifactId&gt;RestService&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
  
      &lt;build&gt;
          &lt;finalName&gt;RestServices&lt;/finalName&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;3.2&lt;/version&gt;
                  &lt;inherited&gt;true&lt;/inherited&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;1.8&lt;/source&gt;
                      &lt;target&gt;1.8&lt;/target&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
      &lt;properties&gt;
          &lt;jersey.version&gt;2.17&lt;/jersey.version&gt;
      &lt;/properties&gt;
      &lt;dependencyManagement&gt;
          &lt;dependencies&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.glassfish.jersey&lt;/groupId&gt;
                  &lt;artifactId&gt;jersey-bom&lt;/artifactId&gt;
                  &lt;version&gt;${jersey.version}&lt;/version&gt;
                  &lt;type&gt;pom&lt;/type&gt;
                  &lt;scope&gt;import&lt;/scope&gt;
              &lt;/dependency&gt;
          &lt;/dependencies&gt;
      &lt;/dependencyManagement&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.jersey.media&lt;/groupId&gt;
              &lt;artifactId&gt;jersey-media-json-jackson&lt;/artifactId&gt;
              &lt;!-- NO VERSION NEEDED BECAUSE OF THE BOM --&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.jersey.containers&lt;/groupId&gt;
              &lt;artifactId&gt;jersey-container-servlet&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.jersey.core&lt;/groupId&gt;
              &lt;artifactId&gt;jersey-server&lt;/artifactId&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
  
  &lt;/project&gt;
  </code></pre>
  
  <p><strong>WEB.XML</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns="http://xmlns.jcp.org/xml/ns/javaee"
      xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
      version="3.1"&gt;
      &lt;display-name&gt;RestService&lt;/display-name&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;Jersey Web Application&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.glassfish.jersey.servlet.ServletContainer&lt;/servlet-class&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;jersey.config.server.provider.packages&lt;/param-name&gt;
              &lt;param-value&gt;com.ws.app&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;Jersey Web Application&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/webapi/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>