title: java-POST method 415 Error
body: <p>I have java EE project.I used Spring Hibernate for server side and Backbone,RequireJS,Jquery for client side on this project.I'm trying to save with POST method but HTTP 415 Error return.</p>
  
  <p>My Get method works fine. I tested it on Postman.</p>
  
  <p>My url: localhost:8080/rest/travel</p>
  
  <p><strong>EDITED</strong></p>
  
  <p>My Resource Class</p>
  
  <pre><code>    @Component
  @Path("/travel")
  public class TravelResource {
  
          @Autowired
          private TravelService travelService;
         @Autowired
        private UserService userService;
  
      @POST
      @Produces(MediaType.APPLICATION_JSON+ ";charset=UTF-8")
      @Consumes(MediaType.APPLICATION_JSON)
          public TravelDTO save(TravelDTO dto) {
          dto.setUser(userService.get(dto.getUser().getUserID()));
            dto.setTravelStart(new Date());
            dto.setTravelEnd(new Date());
  
            return travelService.save(dto);
          }
  
      @PUT
      @Path("/{travelID}")
      @Produces(MediaType.APPLICATION_JSON)
      @Consumes(MediaType.APPLICATION_JSON)
          public TravelDTO edit(@PathParam("travelID") int id, TravelDTO dto) {
          dto.setUser(userService.get(dto.getUser().getUserID()));
          dto.setTravelStart(new Date());
          dto.setTravelEnd(new Date());
  
          return travelService.edit(id,dto);
          }
  
      @DELETE
      @Path("/{travelID}")
      @Produces(MediaType.TEXT_PLAIN)
          public int delete(@PathParam("travelID") int id) {
          travelService.delete(id);
          return id;
          }
      @GET
      @Path("/{travelID}")
      @Produces(MediaType.APPLICATION_JSON)
          public TravelDTO get(int id) {
          return travelService.get(id);
          }
      @GET
      @Produces(MediaType.APPLICATION_JSON)
          public List&lt;TravelDTO&gt; getAll() {
          return travelService.getAll();
  
          }
  
      @GET
      @Path("/search/{travelStart}/{travelEnd}/" )
      @Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8")
      public List&lt;TravelDTO&gt; search(@PathParam("travelStart") Date travelStart,
                                    @PathParam("travelEnd") Date travelEnd )
      {
          return travelService.search(travelStart,travelEnd);
      }
  
  }
  </code></pre>
  
  <p>My DTO Class</p>
  
  <pre><code>public class TravelDTO implements Serializable {
  
      public TravelDTO convert(Travel model) {
          this.setTravelID(model.getTravelID());
          this.setTravelCost(model.getTravelCost());
          this.setTravelStart(model.getTravelStart());
          this.setTravelEnd(model.getTravelEnd());
          this.setLocation(model.getLocation());
          this.setTravelPurpose(model.getTravelPurpose());
         this.setProjectCode(model.getProjectCode());
         this.setUser(new UserDTO().convert(model.getUser()));
          return this;
      }
          private int travelID;
  
         private String projectCode;
  
          private Date travelStart;
  
          private Date travelEnd;
  
          private String Location;
  
          private float travelCost;
  
          private UserDTO user;
  
          private String travelPurpose;
  
      public UserDTO getUser() {
          return user;
      }
  
      public void setUser(UserDTO user) {
          this.user = user;
      }
  
      public String getProjectCode() {
          return projectCode;
      }
  
      public void setProjectCode(String projectCode) {
          this.projectCode = projectCode;
      }
  
      public int getTravelID() {
              return travelID;
          }
  
          public void setTravelID(int travelID) {
              this.travelID = travelID;
          }
  
          public Date getTravelStart() {
              return travelStart;
          }
  
          public void setTravelStart(Date travelStart) {
              this.travelStart = travelStart;
          }
  
          public Date getTravelEnd() {
              return travelEnd;
          }
  
          public void setTravelEnd(Date travelEnd) {
              this.travelEnd = travelEnd;
          }
  
          public String getLocation() {
              return Location;
          }
  
          public void setLocation(String location) {
              Location = location;
          }
  
          public float getTravelCost() {
              return travelCost;
          }
  
          public void setTravelCost(float travelCost) {
              this.travelCost = travelCost;
          }
  
          public String getTravelPurpose() {
              return travelPurpose;
          }
  
          public void setTravelPurpose(String travelPurpose) {
              this.travelPurpose = travelPurpose;
          }
  
      @Override
      public boolean equals(Object o) {
          if (this == o) return true;
          if (o == null || getClass() != o.getClass()) return false;
  
          TravelDTO travelDTO = (TravelDTO) o;
  
          return travelID == travelDTO.travelID;
      }
  
      @Override
      public int hashCode() {
          return travelID;
      }
  }
  </code></pre>
  
  <p>MY SERVICE CLASS</p>
  
  <pre><code>@Service
  public class TravelService {
          @Autowired
          private TravelDAO travelDAO;
  
          @Transactional
          @ResponseBody
          public TravelDTO save(TravelDTO dto) {
              Travel station = new Travel();
              station.convert(dto);
              try {
                  station = travelDAO.persist(station);
              } catch (Exception e) {
                  return null;
              }
              return dto.convert(station);
          }
  
          @Transactional
          @ResponseBody
          public TravelDTO edit(int id, TravelDTO dto) {
              Travel travel = new Travel();
              try {
                  travel.convert(dto);
                  travelDAO.merge(travel);
              } catch (Exception e) {
                  return null;
              }
              return dto.convert(travel);
          }
  
          @Transactional
          @ResponseBody
          public boolean delete(int id) {
              try {
                  Travel travel = travelDAO.find(id);
                  travelDAO.remove(travel);
              } catch (Exception e) {
                  return false;
              }
              return true;
          }
  
          public TravelDTO get(int id) {
              Travel travel;
              try {
                  travel = travelDAO.find(id);
              } catch (Exception e) {
                  return null;
              }
              return new TravelDTO().convert(travel);
          }
  
          public List&lt;TravelDTO&gt; getAll() {
              List&lt;TravelDTO&gt; travelDTOList = new ArrayList&lt;TravelDTO&gt;();
              try {
                  for (Travel travel : travelDAO.findAll())
                      travelDTOList.add(new TravelDTO().convert(travel));
              } catch (Exception e) {
                  return null;
              }
              return travelDTOList;
          }
  
          public List&lt;TravelDTO&gt; search(Date startTime, Date endTime)
                                        {
              List&lt;TravelDTO&gt; travelDTOList = new ArrayList&lt;TravelDTO&gt;();
              try {
                  for (Travel station : travelDAO.search(startTime, endTime))
                      travelDTOList.add(new TravelDTO().convert(station));
              } catch (Exception e) {
                  return null;
              }
              return travelDTOList;
          }
  
  
  
  
  }
  </code></pre>
  
  <p>My data : </p>
  
  <pre><code>model:{"Location":"s","projectCode":"51","travelPurpose":"s","travelStart":"1.1.1","travelEnd":"8.12.2016"}
  </code></pre>
  
  <p>Network TAB</p>
  
  <p><a href="https://i.stack.imgur.com/07cHU.png" rel="nofollow noreferrer">enter image description here</a></p>