【问题标题】:Dropwizard 8.0.1 PUT returns 400Dropwizard 8.0.1 PUT 返回 400
【发布时间】:2016-04-11 21:39:52
【问题描述】:

我在调用 put 资源时收到 400 错误:"code":400,"message":"Unable to process JSON"。我正在使用嵌入式码头服务器

我使用 postman 作为客户端进行测试。

这里是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。

【问题讨论】:

  • 这是在什么服务器上运行的?你如何发送请求?您需要为您的问题添加更多信息。
  • 刚刚添加了更多信息
  • @MasterMind 您能否从您的服务器上的日志中检查并发布错误堆栈跟踪?似乎您的应用程序试图将 json 解析为您的 AdDTO,但由于某种原因它失败了。
  • 没错,有一个异常但没有记录:问题是从客户端发送的对象中有一个额外的属性,但该属性在 AdDTO 中不存在。谢谢@kucing_terbang

标签: java java-8 dropwizard


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-05
    • 2019-07-28
    • 1970-01-01
    • 2019-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多