etang etang - 1 year ago 137
Java Question

Dropwizard Validation Error Message

Is there a way to add variables in Dropwizard's validation error message? Something in the effect of

@ValidationMethod(message=String.format("Url cannot be null, field value = %s", fieldValue))
public boolean isNotValid() {
String fieldValue = this.getFieldValue();
return this.url == null;

I just want to add variable into the error message.

Answer Source

I found an answer. Hibernate 5.1 has error message interpolation which kinda takes care of this.

@Size(min = 0, max = 0, message="${validatedValue} is present"))
public String getErrorMessage() {
    List<String> illegalValues = ImmutableList.of("illegal value");
    return illegalValues;

It's a little hacky, but it solves the problem. Take a look at

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download