title: Spring POST Request Unsupported Media Type 415
body: <p>I have a simple Spring 4 project, based on <a href="https://spring.io/guides/gs/rest-service/" rel="nofollow">this tutorial</a>. I'm trying to implement a RESTful interface. Right now I'm having trouble with handling the POST request. When I try to post a JSON Object, the following error is given:</p>
  
  <pre><code>    {
          "timestamp":1428785473020,
          "status":415,
          "error":"Unsupported Media Type",
          "exception":"org.springframework.web.HttpMediaTypeNotSupportedException",
          "message":"Content type 'application/octet-stream' not supported",
          "path":"/markers/new"
      }
  </code></pre>
  
  <p>If I add the Content-Type header with application/json value, I have this:</p>
  
  <pre><code>{
      "timestamp":1428785073247,
      "status":400,
      "error":"BadRequest",
      "exception":"org.springframework.http.converter.HttpMessageNotReadableException",
      "message":"Could not read JSON: No suitable constructor found for type 
          [simple type, class org.elsys.internetprogramming.trafficspy.server.Marker]: 
          can not instantiate from JSON object (need to add/enable type information?)
          at [Source: java.io.PushbackInputStream@19e19767; line: 1, column: 2]; 
          nested exception is com.fasterxml.jackson.databind.JsonMappingException: 
          No suitable constructor found for type [simple type, class 
          org.elsys.internetprogramming.trafficspy.server.Marker]: can not 
          instantiate from JSON object (need to add/enable type information?)
          at [Source: java.io.PushbackInputStream@19e19767; line: 1, column: 2]",
      "path":"/markers/new"
  }
  </code></pre>
  
  <p>Here is the code:
  <strong>MarkerController.java</strong></p>
  
  <pre><code>@Controller
  public class MarkerController {
      private final AtomicLong id = new AtomicLong();
      private Logger logger = Logger.getLogger(MarkerController.class.getName());
  
      @RequestMapping(value="/markers", method=RequestMethod.GET)
      public @ResponseBody String getMarkers(@RequestParam(value="city", defaultValue="") String city) {
          logger.info("HANDLE GET REQUEST");
          return "{\"id\":\"1\"}";
      }
  
      @RequestMapping(value="/markers/new", method=RequestMethod.POST)
      public @ResponseBody Marker putMarker(@RequestBody Marker marker) {
          logger.info("HANDLE POST REQUEST");
          return marker;
      }
  
  }
  </code></pre>
  
  <p><strong>Marker.java</strong></p>
  
  <pre><code>public class Marker {
      private long id;
      private double longitude;
      private double latitude;
  
      private final String address;
  
      public Marker(long id, double longitude, double latitude, String address) {
          this.id = id;
          this.longitude = longitude;
          this.latitude = latitude;
          this.address = address;
      }
  
      public long getId() {
          return id;
      }
  
      public void setId(long id) {
          this.id = id;
      }
  
      public double getLongitude() {
          return longitude;
      }
  
      public void setLongitude(double longitude) {
          this.longitude = longitude;
      }
  
      public double getLatitude() {
          return latitude;
      }
  
      public void setLatitude(double latitude) {
          this.latitude = latitude;
      }
  
      public String getAddress() {
          return address;
      }
  
      public void setAddress(String address) {
          this.address = address;
      }
  }
  </code></pre>
  
  <p>Do you have any idea what causes this problem  and how to fix it? Thank you!</p>