Skip to content

Commit 5cbd712

Browse files
committed
Fixed the required rule when the request is null
1 parent 7a8cc51 commit 5cbd712

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/main/java/org/javawebstack/validator/Validator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ public ValidationResult validate(ValidationContext context, AbstractElement root
160160
}
161161

162162
private Map<String[], List<ValidationError>> check(ValidationContext context, Map<String[], ValidationConfig> rules, String[] keyPrefix, String[] resolvedKeyPrefix, String[] key, AbstractElement element) {
163+
if (element == null)
164+
element = AbstractNull.INSTANCE;
163165
if (key.length == 0) {
164166
Map<String[], List<ValidationError>> errors = new HashMap<>();
165167
ValidationConfig config = getMapValue(rules, keyPrefix);
@@ -173,8 +175,6 @@ private Map<String[], List<ValidationError>> check(ValidationContext context, Ma
173175
}
174176
return errors;
175177
}
176-
if (element == null)
177-
element = AbstractNull.INSTANCE;
178178
String[] innerKey = new String[key.length - 1];
179179
System.arraycopy(key, 1, innerKey, 0, innerKey.length);
180180
String[] innerKeyPrefix = new String[keyPrefix.length + 1];

src/main/java/org/javawebstack/validator/rule/RequiredRule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
*/
1111
public class RequiredRule implements ValidationRule {
1212
public String validate(ValidationContext context, Field field, AbstractElement value) {
13-
return value != null ? null : "Missing required field";
13+
return !value.isNull() ? null : "Missing required field";
1414
}
1515
}

0 commit comments

Comments
 (0)