我无法接受客户的json。 它显示415错误媒体类型。
型号:
@Entity
@Table(name = "geolocation")
public class Geolocation implements Serializable {
private int id;
private double lat;
private double lon;
public Geolocation(){}
public Geolocation(double lat, double lon) {
this.lat = lat;
this.lon = lon;
}
public Geolocation(int id, double lat, double lon) {
this.id = id;
this.lat = lat;
this.lon = lon;
}
// getters, setters
}
控制器:
@RequestMapping(value="/", method = RequestMethod.GET)
@ResponseBody
public Geolocation test(@RequestBody Geolocation geolocation) {
return geolocation;
}
JSON:
geolocation: {"id": 1,"lat":51.164861,"lon":71.451764}
我包括了jackson-core包,还添加了bean:
<bean id="jsonConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="prefixJson" value="false"/>
<property name="supportedMediaTypes" value="application/json"/>
</bean>
已更新
依赖关系:
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.5.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.4</version>
</dependency>
使用Chrome扩展程序发送的请求&#34;高级休息客户端&#34;