0
votes

I'm getting a 400 Error on calling put on a resource :"code":400,"message":"Unable to process JSON". I'm using the embedded jetty server

I'm using postman as client for testing.

Here is the method in the resource for put method:

@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();
}
}

Here is the Json data sent from the client:

  {
 "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"
]
}

The post and get methods works just fine. I'm using dropwizard 8.0.1 java 8.

1
What server is this running in? How are you sending the request? You need to add more information to your question. - JoeG
Just added more info - Master Mind
@MasterMind could you check and post the error stack trace from the log on your server? seems like your application trying to parse the json into your AdDTO but it failed for some reason. - kucing_terbang
That's right there is an exception but it's not logged : the problem is that there is an extra attribute in the object sent from the client but the attribute does not exists in the AdDTO. Thanks @kucing_terbang - Master Mind

1 Answers

0
votes

Adding getters to all the variables of returned class solved the error for me.