pathTokens.add(constraint.getDescription().getName()); pathTokens.add(schema.getName()); for (PathNode node : path) { if (locale != null && Locale.ENGLISH.getLanguage().equals(locale.getLanguage())) { return constraint.getErrorMessage(invalidValue, locale); } else { return getMessage(Locale.ENGLISH);
/** * This method should be the only one to create {@link ConstraintViolation}. * * @since 7.1 */ private List<ConstraintViolation> validateSimpleTypeField(Schema schema, List<PathNode> path, Field field, Object value) { Type type = field.getType(); assert type.isSimpleType() || type.isListType(); // list type to manage ArrayProperty List<ConstraintViolation> violations = new ArrayList<>(); Set<Constraint> constraints; if (type.isListType()) { // ArrayProperty constraints = ((ListType) type).getFieldType().getConstraints(); } else { constraints = field.getConstraints(); } for (Constraint constraint : constraints) { if (!constraint.validate(value)) { ConstraintViolation violation = new ConstraintViolation(schema, path, constraint, value); violations.add(violation); } } return violations; }
@Override protected void writeEntityBody(Constraint constraint, JsonGenerator jg) throws IOException { Description description = constraint.getDescription(); jg.writeStringField("name", description.getName()); // constraint parameters jg.writeObjectFieldStart("parameters"); for (Map.Entry<String, Serializable> param : description.getParameters().entrySet()) { jg.writeStringField(param.getKey(), param.getValue().toString()); } jg.writeEndObject(); }
protected boolean validateConstraints(Object object) { if (constraints != null) { for (Constraint constraint : constraints) { if (!constraint.validate(object)) { return false; } } } return true; }