'Dropwizard/Jersey resource handler not correctly parsing json data
I'm working on a Dropwizard/Jersey backend. In one particular case, the data sent is not being parsed into the appropriate object. If I add @NotEmpty to a string field, I get a 422 error. Here is the java code:
static final class UpdateGroupParams {
int itemgroupId;
String name;
String displayName;
int priority;
List<Integer> itemIds;
}
@PUT
@Path("{groupId: [0-9]+}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response saveGroup(@NotNull @PathParam("groupId") int groupId, UpdateGroupParams params) {
Using this request:
curl -X PUT -H 'AlliedAuth: xxx' -H 'Content-Type: application/json' -d '{"itemgroupId":1017,"priority":2,"name":"easter","displayName":"Easter","itemIds":[1007,1004,1006,1002,1005]}' -v http://localhost:8080/v1/siteadmin/groups/1017
A breakpoint inside saveGroup() shows that params's values are all 0 or null.
What am I doing wrong?
Solution 1:[1]
The problem was that UpdateGroupParams did not have a constructor. Adding the lombok annotation @AllArgsConstructor fixed the problem.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mark Lilback |
