title: Building controller using Spring RestController and Jackson give me HTTP Stats 406
body: <p>I'm building a rest controller using Spring to handle request and Jackson to serialize data.However I followed tutorial online but I end up getting an error. </p>
  
  <pre><code>HTTP Status 406 -
  
  type Status report
  
  message
  
  description The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers.
  </code></pre>
  
  <p>After Google for a while, I realized that it is because I don't have "application/json" as my "Accept" header in my request:
  <a href="https://i.stack.imgur.com/MhG3i.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MhG3i.png" alt="enter image description here"></a></p>
  
  <p>So I use a tool called Postman to manually add this "Accept" header in the request, send the request again, but still getting the same error:</p>
  
  <p><a href="https://i.stack.imgur.com/LJdk9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LJdk9.png" alt="enter image description here"></a></p>
  
  <p>I'm so confused, I've already included "application/json" as one of accepted data-type, why I still have this data-unsupported error? FYI, here is my Rest Controller class:</p>
  
  <pre><code>package mywebapp.controller;
  
  import java.io.IOException;
  import java.util.List;
  
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.beans.factory.annotation.Qualifier;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.ResponseBody;
  import org.springframework.web.bind.annotation.RestController;
  
  import com.fasterxml.jackson.core.JsonProcessingException;
  import com.fasterxml.jackson.databind.ObjectMapper;
  
  import mywebapp.dao.model.interfaces.PetDao;
  import mywebapp.model.Pet;
  
  @RestController
  @RequestMapping(value = "petJson.htm")
  public class PetControllerAjax {
  
      private static final Logger LOG = LoggerFactory.getLogger(PetController.class);
  
  
      public static Logger getLog() {
          return LOG;
      }
  
      @Autowired
      @Qualifier("PetDaoJpaImpl")
      private PetDao petDao;
  
      public PetDao getPetDao() {
          return petDao;
      }
  
      public void setPetDao(PetDao petDao) {
          this.petDao = petDao;
      }
  
      @RequestMapping(method = RequestMethod.GET)
      public List&lt;Pet&gt; getAllPets() throws IOException {
          getLog().info("Rest Controller activating........");
          List&lt;Pet&gt; petList = getPetDao().getAllPets();
          return petList;
      }
  
  }
  </code></pre>
  
  <p>And here is my Pet entity class:</p>
  
  <pre><code>package mywebapp.model;
  
  import javax.persistence.CascadeType;
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.FetchType;
  import javax.persistence.GeneratedValue;
  import javax.persistence.Id;
  import javax.persistence.JoinColumn;
  import javax.persistence.OneToMany;
  import javax.persistence.OneToOne;
  import javax.persistence.Table;
  
  import com.fasterxml.jackson.annotation.JsonProperty;
  
  import java.util.Date;
  import java.util.Set;
  
  @Entity
  @Table(name = "pet")
  public class Pet {
  
      private int petId;
  
      private String name;
  
      private String owner;
  
      private String species;
  
      private String sex;
  
      private Date birth;
  
      private Date death;
  
      private Set&lt;Toy&gt; toys;  
  
  
      @Id
      @Column(name = "pet_id")
      @GeneratedValue
      @JsonProperty(value="pet_id",required=true)
      public int getId() {
          return petId;
      }
  
      public void setId(int id) {
          this.petId = id;
      }
  
      @JsonProperty(value="pet_name",required=true)
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public String getOwner() {
          return owner;
      }
  
      public void setOwner(String owner) {
          this.owner = owner;
      }
  
      public String getSpecies() {
          return species;
      }
  
      public void setSpecies(String species) {
          this.species = species;
      }
  
      public String getSex() {
          return sex;
      }
  
      public void setSex(String sex) {
          this.sex = sex;
      }
  
      public Date getBirth() {
          return birth;
      }
  
      public void setBirth(Date birth) {
          this.birth = birth;
      }
  
      public Date getDeath() {
          return death;
      }
  
      public void setDeath(Date death) {
          this.death = death;
      }
  
      @OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER,targetEntity=Toy.class, mappedBy="pet")
      public Set&lt;Toy&gt; getToys() {
          return toys;
      }
  
      public void setToys(Set&lt;Toy&gt; toys) {
          this.toys = toys;
      }
  
  
  
  }
  </code></pre>
  
  <p>Anyone knows what's going on here? Any hint will be appreciated, lots of thanks in advance!</p>