【发布时间】:2015-10-17 21:45:41
【问题描述】:
我有以下 POJO:
public class Order {
private String orderCode;
// And many more ... getters and setter
}
还有以下 REST 资源:
@Path("/customers/{customercode}/orders")
public class OrderResource {
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response create(@PathParam("customercode") String customerCode, Order order) {
// ...
}
// ...
}
现在一些客户端将 Order 对象作为 JSON 发送到此 URL。 customerCode 参数设置为预期值,但 order 参数是 null,尽管这里是请求中的有效 JSON 正文。 (我可以在ContainerRequestContext 对象中看到它。)
Jersey 的日志没有说明任何问题(即使在 DEBUG 模式下)。
有什么想法吗?蒂亚! (我正在使用 Jersey 2 和 Jackson)
【问题讨论】:
-
嗯...所以你是从
ContainerRequestContext读到的?这只是为了调试还是已经成为您应用程序的一部分(从上下文中读取请求)? -
@peeskillet 好的。我知道了。我读取了流(作为我的应用程序的一部分),现在它是空的 =>
nullasOrder -
这里有个技巧。将
ContainerRequestContext转换为(ContainerRequest)。使用ContainerRequest.bufferEntity(),然后使用ContainerRequest.readEntity(Order.class) -
有没有办法在不知道任何类类型或媒体类型的情况下获取原始内容(如
ContainerRequestContext.getEntityStream())? -
readEntity(InputStream.class)也许??或String.class如果您总是期待文本数据
标签: java json rest jax-rs jersey-2.0