我正在尝试创建一个 restful-jersey 网络服务。我必须将 JSON 对象传递给 Web 服务。
@POST
@Path("/saveVehicleTrackingData")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public String saveVehicleTrackingData(VehicleTracking vehicleTracking) {
return vehicleTracking.toString();
}
我为项目添加 json 提供程序所做的唯一一件事就是添加了这个 maven 依赖项:
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.5.1</version>
</dependency>
正如这个页面所说:
Due to auto-registration, it should be possible to simply add Maven
dependency (or include jar if using other build systems) and let JAX-RS
implementation discover provider. If this does not work you need to consult
documentation of the JAX-RS implementation for details.
但是自动注册不起作用,我在尝试访问 Web 服务时收到415-Unsupported Media Type错误。是否有关于如何正确注册 json 提供程序的指南?