Skip to content

Commit 49e7465

Browse files
committed
improving documentation of default support
1 parent 3f7ef39 commit 49e7465

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ checking the rest of the JSON document. To toggle this fast-failing validation m
221221

222222
Example:
223223

224-
```
224+
```java
225225
import org.everit.json.schema.Validator;
226226
...
227227
Validator validator = Validator.builder()
@@ -240,15 +240,33 @@ The JSON Schema specification defines the "default" keyword for denoting default
240240
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
241241
by the `SchemaLoaderBuilder#useDefaults(boolean)` method, before loading the schema:
242242

243+
```json
244+
{
245+
"properties": {
246+
"prop": {
247+
"type": "number",
248+
"default": 1
249+
}
250+
}
251+
}
243252
```
253+
254+
255+
```java
256+
JSONObject input = new JSONObject("{}");
257+
System.out.println(input.get("prop")); // prints null
244258
Schema schema = SchemaLoader.builder()
245259
.useDefaults(true)
246260
.schemaJson(rawSchema)
247261
.build()
248262
.load().build();
249263
schema.validate(input);
264+
System.out.println(input.get("prop")); // prints 1
250265
```
251266

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+
252270
## Format validators
253271

254272

0 commit comments

Comments
 (0)