File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -221,7 +221,7 @@ checking the rest of the JSON document. To toggle this fast-failing validation m
221
221
222
222
Example:
223
223
224
- ```
224
+ ``` java
225
225
import org.everit.json.schema.Validator ;
226
226
...
227
227
Validator validator = Validator . builder()
@@ -240,15 +240,33 @@ The JSON Schema specification defines the "default" keyword for denoting default
240
240
affect the validation process. By default this library doesn't set the default values, but if you need this feature, you can turn it on
241
241
by the ` SchemaLoaderBuilder#useDefaults(boolean) ` method, before loading the schema:
242
242
243
+ ``` json
244
+ {
245
+ "properties" : {
246
+ "prop" : {
247
+ "type" : " number" ,
248
+ "default" : 1
249
+ }
250
+ }
251
+ }
243
252
```
253
+
254
+
255
+ ``` java
256
+ JSONObject input = new JSONObject (" {}" );
257
+ System . out. println(input. get(" prop" )); // prints null
244
258
Schema schema = SchemaLoader . builder()
245
259
.useDefaults(true )
246
260
.schemaJson(rawSchema)
247
261
.build()
248
262
.load(). build();
249
263
schema. validate(input);
264
+ System . out. println(input. get(" prop" )); // prints 1
250
265
```
251
266
267
+ If there are some properties missing from ` input ` which have ` "default" ` values in the schema, then they will be set by the validator
268
+ during validation.
269
+
252
270
## Format validators
253
271
254
272
You can’t perform that action at this time.
0 commit comments