bengbengbalabalabeng commented on issue #741:
URL: https://github.com/apache/fesod/issues/741#issuecomment-3670557212

   @alaahong Thank you for getting back to me. I’ve reviewed your points and 
would like to share some ideas:
    
   > 1. Both Apache Bval and Hibernate Validator might tricky on the version 
......
   
   Re: My idea is that the `fesod-bval` module should only depend on the 
standard `jakarta.validation-api`, and `fesod-bval-javax` only on 
`javax.validation-api`. We will not declare a direct, transitive dependency on 
any specific version of Hibernate Validator or Apache BVal.
   
   The decision of which validation implementation to use—and which 
version—should be left entirely to the end-user.
   
   > 2. It's also easy to work with customized validator in invoke, otherwise, 
you have to leave slot in such JSR 380/349/303 implementation for additional 
logic injection
   >    e.g. skip or blocking exception row/file, this is a normal next step if 
any validation failed
   
   Re:
   - In my experience, a common use case is to read the entire file, collect 
all validation failures, and then return a complete report to the user. 
Reporting only the first error found forces the user into a frustrating cycle 
of fixing one issue at a time and re-uploading the file repeatedly. However, I 
agree that different users may have different needs. We can certainly provide 
an enumeration-based strategy to support both modes: `FAIL_FAST` on the first 
validation error, and `COLLECT_ALL` (the default) to gather all errors.
   - The `ValidationErrors` object is bound to the `AnalysisContext`. This 
means that even if users choose not to use the new 
`ValidatingAnalysisEventListener`, they can still access the validation results 
within the standard `invoke` method of their own listeners, preserving maximum 
flexibility.
   
   > 3. Business validator is not less than rule
   >    e.g. in Chinese requirement, we might meet such logic --> validate row 
A via B or C, any practice?
   
   Re: The Bean Validation support this. Users can create a custom annotation 
and implement the `ConstraintValidator` interface to handle complex, 
cross-field validation logic.
   
   For example, to validate that a `discountCode` is not empty when the 
`cardType` is 'VIP':
   
   ```java
   @CompositeValidAnnotation(message = "Discount code is required when card 
type is 'VIP'")
   @Data
   public class ExcelModel {
       private String cardType;
       private String discountCode;
   }
   
   public class CompositeValidValidator implements 
ConstraintValidator<CompositeValidAnnotation, ExcelModel> {
       @Override
       public boolean isValid(ExcelModel value, ConstraintValidatorContext 
context) {
           if ("VIP".equals(value.getCardType())) {
               return value.getDiscountCode() != null && 
!value.getDiscountCode().isEmpty();
           }
           return true;
       }
   }
   
   // ... Annotation definition ...
   @Constraint(validatedBy = CompositeValidValidator.class)
   @Target({ ElementType.TYPE })
   @Retention(RetentionPolicy.RUNTIME)
   public @interface CompositeValidAnnotation {
       // ... standard annotation attributes ...
   }
   ```
   
   My proposed error model directly supports this. The `PropertyError` class is 
designed to capture field-level validation failures, while the base `RowError` 
class is used to hold the results of these class-level.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to