Dropwizard 8.0.1 PUT返回400

时间:2015-05-14 10:44:31

标签: java java-8 dropwizard

我在调用资源时遇到400错误:"代码":400,"消息":"无法处理JSON" 。我正在使用嵌入式码头服务器

我使用邮递员作为客户进行测试。

以下是put方法资源中的方法:

@Path("/Ads")
public class AdResource {

@PUT
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Timed
@UnitOfWork
public Response update(@Valid AdDTO adDto) {
    Ad ad = adDto.buildAd();
    ad = adDao.merge(ad);
    return Response.ok(toJson(ad)).build();
}
}

以下是客户端发送的Json数据:

  {
 "id": 44,
"created": 1430927007000,
"updated": 1430927052000,
"category": "Voiture",
"type": "Berline",
"make": "AUDI",
"model": "A3",
"month": null,
"year": 2002,
"trimVersion": null,
"transmission": "Manuelle",
"fuel": "Diesel",
"door": "4 portes",
"color": "#FC809B",
"metal": true,
"warranty": true,
"publish": false,
"price": 123,
"mileage": 123,
"power": 123,
"description": "<p>df sdfds sdfsdf sdfsdfds sdfsdfsd</p>",
"adImages": [
    {
        "id": 55,
        "created": 1430926983000,
        "updated": 1430926983000,
        "name": "amine.png",
        "url": "http://localhost/assets/photo/55/photo.png",
        "photoUrl": "http://localhost/assets/ad/44/55.jpg",
        "thumbPhotoUrl": "http://localhost/assets/ad/44/55_thumb.jpg"
    },
    {
        "id": 54,
        "created": 1430926982000,
        "updated": 1430926982000,
        "name": "amine2.jpg",
        "url": "http://localhost/assets/photo/54/photo.jpg",
        "photoUrl": "http://localhost/assets/ad/44/54.jpg",
        "thumbPhotoUrl": "http://localhost/assets/ad/44/54_thumb.jpg"
    }
],
"options": [
    "1",
    "2",
    "13",
    "3",
    "14",
    "15"
]
}

post和get方法工作得很好。 我使用dropwizard 8.0.1 java 8。

1 个答案:

答案 0 :(得分:0)

为返回类的所有变量添加getter解决了我的错误。