Skip to content

Commit 8953fe8

Browse files
committed
Rename to json node reader
1 parent 17184ce commit 8953fe8

File tree

6 files changed

+41
-41
lines changed

6 files changed

+41
-41
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,8 @@ Assertions contains the following additional information
353353
| Arguments | The arguments used for generating the message.
354354
| Type | The keyword that generated the message.
355355
| Property | The property name that caused the validation error for example for the `required` keyword. Note that this is not part of the instance location as that points to the instance node.
356-
| Schema Node | The `JsonNode` pointed to by the Schema Location. This is the schema data that caused the input data to fail. It is possible to get the location information by configuring the `JsonSchemaFactory` with a `ObjectReader` that uses the `LocationJsonNodeFactoryFactory` and using `JsonNodes.tokenLocationOf(schemaNode)`.
357-
| Instance Node | The `JsonNode` pointed to by the Instance Location. This is the input data that failed validation. It is possible to get the location information by configuring the `JsonSchemaFactory` with a `ObjectReader` that uses the `LocationJsonNodeFactoryFactory` and using `JsonNodes.tokenLocationOf(instanceNode)`.
356+
| Schema Node | The `JsonNode` pointed to by the Schema Location. This is the schema data that caused the input data to fail. It is possible to get the location information by configuring the `JsonSchemaFactory` with a `JsonNodeReader` that uses the `LocationJsonNodeFactoryFactory` and using `JsonNodes.tokenLocationOf(schemaNode)`.
357+
| Instance Node | The `JsonNode` pointed to by the Instance Location. This is the input data that failed validation. It is possible to get the location information by configuring the `JsonSchemaFactory` with a `JsonNodeReader` that uses the `LocationJsonNodeFactoryFactory` and using `JsonNodes.tokenLocationOf(instanceNode)`.
358358
| Details | Additional details that can be set by custom keyword validator implementations. This is not used by the library.
359359

360360
Annotations contains the following additional information
@@ -367,7 +367,7 @@ Annotations contains the following additional information
367367

368368
The library can be configured to store line and column information in the `JsonNode` instances for the instance and schema nodes. This will adversely affect performance and is not configured by default.
369369

370-
This is done by configuring a `ObjectReader` that uses the `LocationJsonNodeFactoryFactory`on the `JsonSchemaFactory`. The `JsonLocation` information can then be retrieved using `JsonNodes.tokenLocationOf(jsonNode)`.
370+
This is done by configuring a `JsonNodeReader` that uses the `LocationJsonNodeFactoryFactory`on the `JsonSchemaFactory`. The `JsonLocation` information can then be retrieved using `JsonNodes.tokenLocationOf(jsonNode)`.
371371

372372
```java
373373
String schemaData = "{\r\n"
@@ -383,7 +383,7 @@ String inputData = "{\r\n"
383383
+ " \"startDate\": \"1\"\r\n"
384384
+ "}";
385385
JsonSchemaFactory factory = JsonSchemaFactory.getInstance(VersionFlag.V202012,
386-
builder -> builder.objectReader(ObjectReader.builder().locationAware().build()));
386+
builder -> builder.jsonNodeReader(JsonNodeReader.builder().locationAware().build()));
387387
SchemaValidatorsConfig config = new SchemaValidatorsConfig();
388388
config.setPathType(PathType.JSON_POINTER);
389389
JsonSchema schema = factory.getSchema(schemaData, InputFormat.JSON, config);

src/main/java/com/networknt/schema/JsonSchemaFactory.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import com.networknt.schema.resource.SchemaMapper;
2626
import com.networknt.schema.resource.SchemaMappers;
2727
import com.networknt.schema.serialization.JsonMapperFactory;
28-
import com.networknt.schema.serialization.ObjectReader;
28+
import com.networknt.schema.serialization.JsonNodeReader;
2929
import com.networknt.schema.serialization.YamlMapperFactory;
3030

3131
import org.slf4j.Logger;
@@ -55,7 +55,7 @@ public class JsonSchemaFactory {
5555
public static class Builder {
5656
private ObjectMapper jsonMapper = null;
5757
private ObjectMapper yamlMapper = null;
58-
private ObjectReader objectReader = null;
58+
private JsonNodeReader jsonNodeReader = null;
5959
private String defaultMetaSchemaIri;
6060
private final ConcurrentMap<String, JsonMetaSchema> metaSchemas = new ConcurrentHashMap<String, JsonMetaSchema>();
6161
private SchemaLoaders.Builder schemaLoadersBuilder = null;
@@ -64,17 +64,17 @@ public static class Builder {
6464
private JsonMetaSchemaFactory metaSchemaFactory = null;
6565

6666
/**
67-
* Sets the object reader to read the data.
67+
* Sets the json node reader to read the data.
6868
* <p>
6969
* If set this takes precedence over the configured json mapper and yaml mapper.
7070
* <p>
71-
* A location aware object reader can be created using ObjectReader.builder().locationAware().build().
71+
* A location aware object reader can be created using JsonNodeReader.builder().locationAware().build().
7272
*
73-
* @param objectReader the object reader
73+
* @param jsonNodeReader the object reader
7474
* @return the builder
7575
*/
76-
public Builder objectReader(ObjectReader objectReader) {
77-
this.objectReader = objectReader;
76+
public Builder jsonNodeReader(JsonNodeReader jsonNodeReader) {
77+
this.jsonNodeReader = jsonNodeReader;
7878
return this;
7979
}
8080

@@ -172,7 +172,7 @@ public JsonSchemaFactory build() {
172172
return new JsonSchemaFactory(
173173
jsonMapper,
174174
yamlMapper,
175-
objectReader,
175+
jsonNodeReader,
176176
defaultMetaSchemaIri,
177177
schemaLoadersBuilder,
178178
schemaMappersBuilder,
@@ -185,7 +185,7 @@ public JsonSchemaFactory build() {
185185

186186
private final ObjectMapper jsonMapper;
187187
private final ObjectMapper yamlMapper;
188-
private final ObjectReader objectReader;
188+
private final JsonNodeReader jsonNodeReader;
189189
private final String defaultMetaSchemaIri;
190190
private final SchemaLoaders.Builder schemaLoadersBuilder;
191191
private final SchemaMappers.Builder schemaMappersBuilder;
@@ -201,7 +201,7 @@ public JsonSchemaFactory build() {
201201
private JsonSchemaFactory(
202202
ObjectMapper jsonMapper,
203203
ObjectMapper yamlMapper,
204-
ObjectReader objectReader,
204+
JsonNodeReader jsonNodeReader,
205205
String defaultMetaSchemaIri,
206206
SchemaLoaders.Builder schemaLoadersBuilder,
207207
SchemaMappers.Builder schemaMappersBuilder,
@@ -218,7 +218,7 @@ private JsonSchemaFactory(
218218
}
219219
this.jsonMapper = jsonMapper;
220220
this.yamlMapper = yamlMapper;
221-
this.objectReader = objectReader;
221+
this.jsonNodeReader = jsonNodeReader;
222222
this.defaultMetaSchemaIri = defaultMetaSchemaIri;
223223
this.schemaLoadersBuilder = schemaLoadersBuilder;
224224
this.schemaMappersBuilder = schemaMappersBuilder;
@@ -311,7 +311,7 @@ public static Builder builder(final JsonSchemaFactory blueprint) {
311311
.defaultMetaSchemaIri(blueprint.defaultMetaSchemaIri)
312312
.jsonMapper(blueprint.jsonMapper)
313313
.yamlMapper(blueprint.yamlMapper)
314-
.objectReader(blueprint.objectReader);
314+
.jsonNodeReader(blueprint.jsonNodeReader);
315315
if (blueprint.schemaLoadersBuilder != null) {
316316
builder.schemaLoadersBuilder = SchemaLoaders.builder().with(blueprint.schemaLoadersBuilder);
317317
}
@@ -463,18 +463,18 @@ protected JsonMetaSchema loadMetaSchema(String iri, SchemaValidatorsConfig confi
463463
}
464464

465465
JsonNode readTree(String content, InputFormat inputFormat) throws IOException {
466-
if (this.objectReader == null) {
466+
if (this.jsonNodeReader == null) {
467467
return getObjectMapper(inputFormat).readTree(content);
468468
} else {
469-
return this.objectReader.readTree(content, inputFormat);
469+
return this.jsonNodeReader.readTree(content, inputFormat);
470470
}
471471
}
472472

473473
JsonNode readTree(InputStream content, InputFormat inputFormat) throws IOException {
474-
if (this.objectReader == null) {
474+
if (this.jsonNodeReader == null) {
475475
return getObjectMapper(inputFormat).readTree(content);
476476
} else {
477-
return this.objectReader.readTree(content, inputFormat);
477+
return this.jsonNodeReader.readTree(content, inputFormat);
478478
}
479479
}
480480

src/main/java/com/networknt/schema/serialization/DefaultObjectReader.java renamed to src/main/java/com/networknt/schema/serialization/DefaultJsonNodeReader.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
import com.networknt.schema.utils.JsonNodes;
1212

1313
/**
14-
* Default {@link ObjectReader}.
14+
* Default {@link JsonNodeReader}.
1515
*/
16-
public class DefaultObjectReader implements ObjectReader {
16+
public class DefaultJsonNodeReader implements JsonNodeReader {
1717
protected final ObjectMapper jsonMapper;
1818
protected final ObjectMapper yamlMapper;
1919
protected final JsonNodeFactoryFactory jsonNodeFactoryFactory;
@@ -25,7 +25,7 @@ public class DefaultObjectReader implements ObjectReader {
2525
* @param yamlMapper the yaml mapper
2626
* @param jsonNodeFactoryFactory the json node factory factory
2727
*/
28-
protected DefaultObjectReader(ObjectMapper jsonMapper, ObjectMapper yamlMapper,
28+
protected DefaultJsonNodeReader(ObjectMapper jsonMapper, ObjectMapper yamlMapper,
2929
JsonNodeFactoryFactory jsonNodeFactoryFactory) {
3030
this.jsonMapper = jsonMapper;
3131
this.yamlMapper = yamlMapper;
@@ -84,7 +84,7 @@ protected ObjectMapper getObjectMapper(InputFormat inputFormat) {
8484
}
8585

8686
/**
87-
* Gets the builder for {@link DefaultObjectReader}.
87+
* Gets the builder for {@link DefaultJsonNodeReader}.
8888
*
8989
* @return the builder
9090
*/
@@ -93,7 +93,7 @@ public static Builder builder() {
9393
}
9494

9595
/**
96-
* Builder support for {@link ObjectReader}.
96+
* Builder support for {@link JsonNodeReader}.
9797
*
9898
* @param <T> the super type
9999
*/
@@ -143,7 +143,7 @@ public T jsonNodeFactoryFactory(JsonNodeFactoryFactory jsonNodeFactoryFactory) {
143143
}
144144

145145
/**
146-
* Builder for {@link DefaultObjectReader}.
146+
* Builder for {@link DefaultJsonNodeReader}.
147147
*/
148148
public static class Builder extends BuilderSupport<Builder> {
149149

@@ -162,12 +162,12 @@ public Builder locationAware() {
162162
}
163163

164164
/**
165-
* Builds the {@link ObjectReader}.
165+
* Builds the {@link JsonNodeReader}.
166166
*
167167
* @return the object reader
168168
*/
169-
public ObjectReader build() {
170-
return new DefaultObjectReader(this.jsonMapper, this.yamlMapper, this.jsonNodeFactoryFactory);
169+
public JsonNodeReader build() {
170+
return new DefaultJsonNodeReader(this.jsonMapper, this.yamlMapper, this.jsonNodeFactoryFactory);
171171
}
172172
}
173173
}

src/main/java/com/networknt/schema/serialization/ObjectReader.java renamed to src/main/java/com/networknt/schema/serialization/JsonNodeReader.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
import com.networknt.schema.InputFormat;
2323

2424
/**
25-
* Object reader.
25+
* Reader for reading content to {@link JsonNode}.
2626
*/
27-
public interface ObjectReader {
27+
public interface JsonNodeReader {
2828

2929
/**
3030
* Deserialize content as a tree.
@@ -47,11 +47,11 @@ public interface ObjectReader {
4747
JsonNode readTree(InputStream content, InputFormat inputFormat) throws IOException;
4848

4949
/**
50-
* Creates a builder for {@link ObjectReader}.
50+
* Creates a builder for {@link JsonNodeReader}.
5151
*
5252
* @return the builder
5353
*/
54-
public static DefaultObjectReader.Builder builder() {
55-
return DefaultObjectReader.builder();
54+
public static DefaultJsonNodeReader.Builder builder() {
55+
return DefaultJsonNodeReader.builder();
5656
}
5757
}

src/test/java/com/networknt/schema/serialization/DefaultObjectReaderTest.java renamed to src/test/java/com/networknt/schema/serialization/DefaultJsonNodeReaderTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
/**
3030
* Test for Default Object Reader.
3131
*/
32-
class DefaultObjectReaderTest {
32+
class DefaultJsonNodeReaderTest {
3333
@Test
3434
void location() throws JsonParseException, IOException {
3535
String schemaData = "{\r\n"
@@ -41,7 +41,7 @@ void location() throws JsonParseException, IOException {
4141
+ " }\r\n"
4242
+ " }\r\n"
4343
+ "}";
44-
JsonNode jsonNode = ObjectReader.builder().locationAware().build().readTree(schemaData, InputFormat.JSON);
44+
JsonNode jsonNode = JsonNodeReader.builder().locationAware().build().readTree(schemaData, InputFormat.JSON);
4545
JsonNode idNode = jsonNode.at("/$id");
4646
JsonLocation location = JsonNodes.tokenLocationOf(idNode);
4747
assertEquals(2, location.getLineNr());
@@ -69,7 +69,7 @@ void jsonLocation() throws IOException {
6969
+ " }\r\n"
7070
+ " }\r\n"
7171
+ "}";
72-
JsonNode jsonNode = ObjectReader.builder().locationAware().build().readTree(schemaData, InputFormat.JSON);
72+
JsonNode jsonNode = JsonNodeReader.builder().locationAware().build().readTree(schemaData, InputFormat.JSON);
7373

7474
JsonLocation formatSchemaNodeTokenLocation = JsonNodes.tokenLocationOf(jsonNode.at("/properties/startDate/format"));
7575
JsonLocation minLengthSchemaNodeTokenLocation = JsonNodes.tokenLocationOf(jsonNode.at("/properties/startDate/minLength"));
@@ -90,7 +90,7 @@ void yamlLocation() throws IOException {
9090
+ " format: 'date'\r\n"
9191
+ " minLength: 6\r\n"
9292
+ "";
93-
JsonNode jsonNode = ObjectReader.builder().locationAware().build().readTree(schemaData, InputFormat.YAML);
93+
JsonNode jsonNode = JsonNodeReader.builder().locationAware().build().readTree(schemaData, InputFormat.YAML);
9494

9595
JsonLocation formatSchemaNodeTokenLocation = JsonNodes.tokenLocationOf(jsonNode.at("/properties/startDate/format"));
9696
JsonLocation minLengthSchemaNodeTokenLocation = JsonNodes.tokenLocationOf(jsonNode.at("/properties/startDate/minLength"));

src/test/java/com/networknt/schema/utils/JsonNodesTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
import com.networknt.schema.SpecVersion.VersionFlag;
4141
import com.networknt.schema.ValidationMessage;
4242
import com.networknt.schema.serialization.JsonMapperFactory;
43-
import com.networknt.schema.serialization.ObjectReader;
43+
import com.networknt.schema.serialization.JsonNodeReader;
4444
import com.networknt.schema.serialization.node.LocationJsonNodeFactoryFactory;
4545
/**
4646
* Tests for JsonNodes.
@@ -90,7 +90,7 @@ void jsonLocation() {
9090
+ " \"startDate\": \"1\"\r\n"
9191
+ "}";
9292
JsonSchemaFactory factory = JsonSchemaFactory.getInstance(VersionFlag.V202012,
93-
builder -> builder.objectReader(ObjectReader.builder().locationAware().build()));
93+
builder -> builder.jsonNodeReader(JsonNodeReader.builder().locationAware().build()));
9494
SchemaValidatorsConfig config = new SchemaValidatorsConfig();
9595
config.setPathType(PathType.JSON_POINTER);
9696
JsonSchema schema = factory.getSchema(schemaData, InputFormat.JSON, config);
@@ -139,7 +139,7 @@ void yamlLocation() {
139139
+ "startDate: '1'\r\n"
140140
+ "";
141141
JsonSchemaFactory factory = JsonSchemaFactory.getInstance(VersionFlag.V202012,
142-
builder -> builder.objectReader(ObjectReader.builder().locationAware().build()));
142+
builder -> builder.jsonNodeReader(JsonNodeReader.builder().locationAware().build()));
143143
SchemaValidatorsConfig config = new SchemaValidatorsConfig();
144144
config.setPathType(PathType.JSON_POINTER);
145145
JsonSchema schema = factory.getSchema(schemaData, InputFormat.YAML, config);

0 commit comments

Comments
 (0)