class SizeConstraintValidationErrorDescriptorBuilder implements ValidationErrorDescriptorBuilder<Size> {

    @Override
    public ErrorDescriptor build(ConstraintViolation<Size> violation) {
        final Size annotation = (Size) violation.getConstraintDescriptor().getAnnotation();
        final String propertyPath = violation.getPropertyPath().toString();
        final String invalidValue = violation.getInvalidValue().toString();

        final String proprtyName = propertyPath.substring(propertyPath.lastIndexOf(".") + 1);
        final ErrorDescriptor errorDescriptor = new ErrorDescriptor().
                setErrorCode(annotation.message()).
                setMessage("Length of field \"" + proprtyName + "\" breaks length limit.");
        errorDescriptor.addProperties(new ClientProperty("invalidValue", invalidValue),
                new ClientProperty("actualLength", String.valueOf(invalidValue.length())),
                new ClientProperty("maxLimit", String.valueOf(annotation.max())),
                new ClientProperty("minLimit", String.valueOf(annotation.min())),
                new ClientProperty("propertyPath", propertyPath));

        return errorDescriptor;
    }

}