validation

Spring Boot validation - one from two not null

非 Y 不嫁゛ 提交于 2020-08-04 10:35:45
问题 I'm trying to validate if one of two fields are not null in Spring Boot? I have set that in the method class for the main object: @NotNull(message = "Username field is required") private String username; @NotNull(message = "Email field is required") private String email; but that will require to have both fields not null. Then I went with custom validation described here https://lmonkiewicz.com/programming/get-noticed-2017/spring-boot-rest-request-validation/ but I wasn't able to get that

Spring Boot validation - one from two not null

坚强是说给别人听的谎言 提交于 2020-08-04 10:35:21
问题 I'm trying to validate if one of two fields are not null in Spring Boot? I have set that in the method class for the main object: @NotNull(message = "Username field is required") private String username; @NotNull(message = "Email field is required") private String email; but that will require to have both fields not null. Then I went with custom validation described here https://lmonkiewicz.com/programming/get-noticed-2017/spring-boot-rest-request-validation/ but I wasn't able to get that

Spring RestController : reject request with unknown fields

余生长醉 提交于 2020-08-04 07:21:20
问题 I have the following endpoint : import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; import static org.springframework.web.bind.annotation.RequestMethod.POST; @RestController public class TestController { @RequestMapping(value = "/persons", method = POST, consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) public ResponseEntity<Integer> create(@RequestBody

Spring RestController : reject request with unknown fields

[亡魂溺海] 提交于 2020-08-04 07:20:38
问题 I have the following endpoint : import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; import static org.springframework.web.bind.annotation.RequestMethod.POST; @RestController public class TestController { @RequestMapping(value = "/persons", method = POST, consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) public ResponseEntity<Integer> create(@RequestBody

(Best Practice) FluentValidation and Checking Duplicate Entities

江枫思渺然 提交于 2020-08-04 03:38:50
问题 I have a table (junction table) with 3 primary keys so when I want to check duplicate records , I must check 3 properties together I wrote a method like this private bool IsDuplicate(long roleId, long componentGroupId, long operationId) { var business = new RoleGroupBusiness(); var result = business.Where(x => x.RoleID == roleId && x.ComponentGroupID == componentGroupId && x.OperationID == operationId).Any(); return result; } and I have a FluentValidator class like this : public class

How to test a Validator which implements ConstraintValidator in java?

冷暖自知 提交于 2020-08-04 02:36:13
问题 I have an "AllowedValuesValidator.java" class: public class AllowedValuesValidator implements ConstraintValidator<AllowedValues, String> { String[] values; String defaultValue; @Override public void initialize(AllowedValues constraintAnnotation) { values = constraintAnnotation.allowedValues(); defaultValue = constraintAnnotation.defaultValue(); } @Override public boolean isValid(String value, ConstraintValidatorContext context) { if (!StringUtils.isEmpty(defaultValue) && StringUtils.isEmpty

How to test a Validator which implements ConstraintValidator in java?

…衆ロ難τιáo~ 提交于 2020-08-04 02:32:47
问题 I have an "AllowedValuesValidator.java" class: public class AllowedValuesValidator implements ConstraintValidator<AllowedValues, String> { String[] values; String defaultValue; @Override public void initialize(AllowedValues constraintAnnotation) { values = constraintAnnotation.allowedValues(); defaultValue = constraintAnnotation.defaultValue(); } @Override public boolean isValid(String value, ConstraintValidatorContext context) { if (!StringUtils.isEmpty(defaultValue) && StringUtils.isEmpty

How to test a Validator which implements ConstraintValidator in java?

為{幸葍}努か 提交于 2020-08-04 02:32:37
问题 I have an "AllowedValuesValidator.java" class: public class AllowedValuesValidator implements ConstraintValidator<AllowedValues, String> { String[] values; String defaultValue; @Override public void initialize(AllowedValues constraintAnnotation) { values = constraintAnnotation.allowedValues(); defaultValue = constraintAnnotation.defaultValue(); } @Override public boolean isValid(String value, ConstraintValidatorContext context) { if (!StringUtils.isEmpty(defaultValue) && StringUtils.isEmpty

Laravel validation: exists two column same row

人走茶凉 提交于 2020-08-03 09:17:59
问题 Is there a way of referencing another field when specifying the exists validation rule in Laravel? My request : public function rules() { return [ 'numero_de_somme' => 'unique:personnels,numero_de_somme|exists:fonctionnaire,num_somme', 'cin' => 'unique:personnels,cin|exists:fonctionnaire,cin', ]; } in my validation rules I want to be able to make sure that: num_somme exists within the fonctionnaire table cin exists within the fonctionnaire table and cin input must be on the same row of the

Override ValidateAsync in UserValidator.cs for .NET Core Identity 2.1

心不动则不痛 提交于 2020-08-02 20:53:48
问题 I'm customizing the validation for username to allow the same username (non-unique). This is with an additional field "Deleted" as a soft delete to identity user. So the customization involves changing the current validation to check if the username already exist and deleted is false to only trigger DuplicateUserName error. What I've done is create a CustomUserValidator class, and override the ValidateAsync method in UserValidator.cs as well as the ValidateUserName method. Below is the code: