2015-05-14 78 views
0

我在調用放置資源時出現400錯誤:「code」:400,「message」:「無法處理JSON」。我正在使用嵌入式碼頭服務器Dropwizard 8.0.1 PUT返回400

我使用郵遞員作爲客戶端進行測試。

這裏是在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" 
] 
} 

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

+0

運行什麼服務器?你如何發送請求?您需要爲您的問題添加更多信息。 – JoeG

+0

剛剛添加更多信息 –

+1

@MasterMind能否檢查並從服務器上的日誌中發佈錯誤堆棧跟蹤?看起來像你的應用程序試圖解析JSON到你的'AdDTO'中,但由於某種原因它失敗了。 –

回答

0

將getters添加到返回類的所有變量中解決了我的錯誤。