I have a dropwizard service that accepts a PUT of a JSON document representing a bean. I make use of constraint annotations in the bean implementation and use the @Valid annotation in my Resource method:
@PUT
public Response write(@Valid MyBean bean);
and everything works rather well.
Now however, I want to pass an array of objects in the JSON. I simply changed the method signature to
@PUT
public Response write(@Valid List<MyBean> beans);
and it generally works, but if there are validation errors then the response is not very user friendly. For example, If I post in 100 beans in the array, and one of them is missing a 'name' property, then the response is
{"errors":["name may not be empty"]}
without any indication of which bean in the request has the problem.
Is there a way to overcome this?
Failing that, is there a way for me to obtain a validator in the Resource class so that I can handle all this myself?