REST中,我们可以把接受POST请求的方式写成如下的方式:
@POST
@Consumes(MediaType.APPLICATION_JSON)public Response createProduct(CreateProductJson createProductJson, @Context UriInfo uriInfo) {
CreateProductJson就是我们服务器用来接收CreateProudct这样一个请求的JSON表达方式,然后我们可以通过createProductJson.getProduct()这样类似的方法得到product对象,然后再将围绕着product这一领域对象进行处理
这样看似还不错,CreateProductJson就类似成为了我们的DTO对象,但是这里有一个问题就是CreateProductJson的容错性比较差。假如,我们当前的product需要两个字段:name、price。但是客户端如果多传输给我们了一个description,那么很有可能我的反序列化CreateProductJson对象