我正在尝试使用Bean Validation使用自定义消息,但JAX-RS资源不会返回我的自定义消息。我做错了什么?
invoice.value.notnull=Invoice value must be informed.
该文件位于src/main/resources
@Path("/invoice")
public class InvoiceResource {
@POST
public void post(@Valid InvoiceRequest request) {
/* stuff */
}
}
public class InvoiceRequest {
@NotNull(message = "invoice.value.notnull")
private Double value;
}
答案 0 :(得分:0)
发现问题是我在bean参数中声明了消息。消息ID必须在大括号"{ ... }"
:
@NotNull(message = "{invoice.value.notnull}")
我们如何使用正确的消息获得正确的JSON响应:
{
"exception": null,
"fieldViolations": [],
"propertyViolations": [],
"classViolations": [],
"parameterViolations": [
{
"constraintType": "PARAMETER",
"path": "post.arg0.value",
"message": "Invoice value must be informed",
"value": ""
}
],
"returnValueViolations": []
}