【发布时间】:2015-06-12 02:17:19
【问题描述】:
在 Dropwizard 中,我对资源方法使用 @Valid 注释:
public class Address {
@NotNull
String street
...
}
@Path("/address")
@Produces(MediaType.APPLICATION_JSON)
public class AddressResource {
@POST
public MyResponse addAddress(@Valid Address address) {
if (address == null) {
throw new WebApplicationException("address was null");
}
...
}
}
在应用程序启动时,我注册了一个自定义 WebApplicationExceptionMapper,它处理 WebApplicationExceptions。因此,对于值为 null 的地址,会在生成有用响应的映射器中引发和处理异常。但是,如果地址不为空但street 为空,Dropwizard 会自动生成响应并将其发送给客户端(我不喜欢)。
我如何干扰这个响应,以便最终它也被映射器处理?
【问题讨论】:
标签: java bean-validation jersey-2.0 dropwizard validationerror