File tree Expand file tree Collapse file tree 3 files changed +35
-1
lines changed
main/java/org/everit/json/schema
test/java/org/everit/json/schema Expand file tree Collapse file tree 3 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,14 @@ private static boolean isNull(Object obj) {
24
24
this .failureReporter = new CollectingFailureReporter (schema );
25
25
}
26
26
27
+ @ Override
28
+ void visit (Schema schema ) {
29
+ if (schema .isNullable () == Boolean .FALSE && isNull (subject )) {
30
+ failureReporter .failure ("value cannot be null" , "nullable" );
31
+ }
32
+ super .visit (schema );
33
+ }
34
+
27
35
ValidatingVisitor (Object subject , ValidationFailureReporter failureReporter ) {
28
36
this .subject = subject ;
29
37
this .failureReporter = failureReporter ;
Original file line number Diff line number Diff line change
1
+ package org .everit .json .schema ;
2
+
3
+ import org .json .JSONObject ;
4
+ import org .junit .Test ;
5
+
6
+ public class NullableValidationTest {
7
+
8
+ @ Test
9
+ public void testNullableFalse_JSONNull () {
10
+ TestSupport .failureOf (StringSchema .builder ().requiresString (false ).nullable (false ))
11
+ .input (JSONObject .NULL )
12
+ .expectedKeyword ("nullable" )
13
+ .expectedMessageFragment ("value cannot be null" )
14
+ .expect ();
15
+ }
16
+
17
+ @ Test
18
+ public void testNullableFalse_nullReference () {
19
+ TestSupport .failureOf (StringSchema .builder ().requiresString (false ).nullable (false ))
20
+ .input (null )
21
+ .expectedKeyword ("nullable" )
22
+ .expectedMessageFragment ("value cannot be null" )
23
+ .expect ();
24
+ }
25
+
26
+ }
Original file line number Diff line number Diff line change 28
28
import static org .junit .Assert .assertTrue ;
29
29
30
30
public class StringSchemaTest {
31
-
31
+
32
32
private static Schema loadWithNullableSupport (JSONObject rawSchemaJson ) {
33
33
return SchemaLoader .builder ().nullableSupport (true ).schemaJson (rawSchemaJson ).build ().load ().build ();
34
34
}
You can’t perform that action at this time.
0 commit comments