0
我將jersey 1.2與jersey-server,jersey-json和jersey-spring一起使用來創建REST服務。jax-rs地圖查詢參數對象
我的一個服務
@Path("test")
public class TestViewRestController {
@GET
@Path("t1")
@Produces(MediaType.APPLICATION_JSON)
public RetPojo getPojo(
@QueryParam("token") @DefaultValue("null") String token,
@QueryParam("pojo") ParamPojo pojo,
@QueryParam("param2") @DefaultValue("null") String param2
) {
//do some stuff
}
}
我創建了一個提供者:
@Provider
@Consumes(MediaType.APPLICATION_JSON)
public class MessageBodyReaderJSON implements MessageBodyReader<APojo> {
/**
* {@inheritDoc}
*/
public boolean isReadable(Class<?> type, Type genericType,
Annotation[] annotations, MediaType mediaType) {
return true;
}
/**
* {@inheritDoc}
*/
public APojo readFrom(Class<APojo> type, Type genericType,
Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
throws IOException {
APojo p = new ObjectMapper().readValue(entityStream, APojo.class);
return p;
}
}
但是,當我開始我的Web服務器下列錯誤時拋出拋出:
com.sun.jersey.api.container.ContainerException:
Method, public my.package.TestViewRestController.getPojo(java.lang.String, my.package.APojo, java.lang.String),
annotated with GET of resource, class my.package.TestViewRestController,
is not recognized as valid Java method annotated with @HttpMethod.
當我用一個String來替換APojo參數。看來提供者被忽略了。
隨着澤西島的最新版本我沒有得到這個問題(我也沒有聲明提供程序),但我無法升級,因爲應用程序需要在Java 5上運行(並且最後一個澤西運行只從Java 6)。
有什麼想法?
謝謝
我設法用澤西** 1.16 **和傑克遜做servlet的init-param'com.sun.jersey.api.json.POJOMappingFeature'爲true。映射是自動完成的。但是運行在jdk5上的球衣的最後一個版本是球衣** 1.2 **,它不會進行自動映射。 – krampstudio
有趣。我想知道映射是如何完成的 - 我想只能解析JSON,URL編碼可以處理大括號等。所以這只是大小限制,對於小文檔來說可能沒問題。 – StaxMan