使用 JAX-RS 同时使用 Text/plain 和 Application/json?
Consuming Both of Text/plain and Application/json with JAX-RS?
我的网络服务中有以下方法只接受 text/plain:
@PUT
@Path("/{resourceName}")
@Produces("text/plain")
@Consumes("text/plain")
public String putResources(...){
...
}
我要做的是以某种方式更改它,以便也接受 json 参数。可能吗?
如果你想同时支持两者,你必须这样使用。
@Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN })
@Consumes({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN })
我的网络服务中有以下方法只接受 text/plain:
@PUT
@Path("/{resourceName}")
@Produces("text/plain")
@Consumes("text/plain")
public String putResources(...){
...
}
我要做的是以某种方式更改它,以便也接受 json 参数。可能吗?
如果你想同时支持两者,你必须这样使用。
@Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN })
@Consumes({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN })