Skip to content

Commit

Permalink
Deprecate setting jsonMapper and yamlMapper on JsonSchemaFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
justin-tay committed Jun 14, 2024
1 parent 0b7d1b8 commit d77dacd
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 29 deletions.
8 changes: 8 additions & 0 deletions src/main/java/com/networknt/schema/JsonSchemaFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public static class Builder {
* Sets the object reader to read the data.
* <p>
* If set this takes precedence over the configured json mapper and yaml mapper.
* <p>
* A location aware object reader can be created using ObjectReader.builder().locationAware().build().
*
* @param objectReader the object reader
* @return the builder
Expand All @@ -80,10 +82,13 @@ public Builder objectReader(ObjectReader objectReader) {
* Sets the json mapper to read the data.
* <p>
* If the object reader is set this will not be used.
* <p>
* This is deprecated use a object reader instead.
*
* @param jsonMapper the json mapper
* @return the builder
*/
@Deprecated
public Builder jsonMapper(final ObjectMapper jsonMapper) {
this.jsonMapper = jsonMapper;
return this;
Expand All @@ -93,10 +98,13 @@ public Builder jsonMapper(final ObjectMapper jsonMapper) {
* Sets the yaml mapper to read the data.
* <p>
* If the object reader is set this will not be used.
* <p>
* This is deprecated use a object reader instead.
*
* @param yamlMapper the yaml mapper
* @return the builder
*/
@Deprecated
public Builder yamlMapper(final ObjectMapper yamlMapper) {
this.yamlMapper = yamlMapper;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@

package com.networknt.schema;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.networknt.schema.SpecVersion.VersionFlag;
import com.networknt.schema.regex.JDKRegularExpressionFactory;
import com.networknt.schema.regex.JoniRegularExpressionFactory;
import com.networknt.schema.serialization.JsonMapperFactory;
import com.networknt.schema.suite.TestCase;
import com.networknt.schema.suite.TestSource;
import com.networknt.schema.suite.TestSpec;
Expand Down Expand Up @@ -48,9 +46,6 @@

public abstract class AbstractJsonSchemaTestSuite extends HTTPServiceSupport {


protected ObjectMapper mapper = JsonMapperFactory.getInstance();

private static String toForwardSlashPath(Path file) {
return file.toString().replace('\\', '/');
}
Expand Down Expand Up @@ -190,7 +185,6 @@ private JsonSchemaFactory buildValidatorFactory(VersionFlag defaultVersion, Test
JsonSchemaFactory base = JsonSchemaFactory.getInstance(specVersion);
return JsonSchemaFactory
.builder(base)
.jsonMapper(this.mapper)
.schemaMappers(schemaMappers -> schemaMappers
.mapPrefix("https://", "http://")
.mapPrefix("http://json-schema.org", "resource:"))
Expand Down
1 change: 0 additions & 1 deletion src/test/java/com/networknt/schema/Issue285Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class Issue285Test {
private ObjectMapper mapper = new ObjectMapper();
private JsonSchemaFactory schemaFactory = JsonSchemaFactory
.builder(JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V201909))
.jsonMapper(mapper)
.schemaMappers(schemaMappers -> schemaMappers
.mapPrefix("http://json-schema.org", "resource:")
.mapPrefix("https://json-schema.org", "resource:"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private void setupSchema() throws IOException {
SchemaValidatorsConfig schemaValidatorsConfig = new SchemaValidatorsConfig();
schemaValidatorsConfig.setFailFast(true);
JsonSchemaFactory schemaFactory = JsonSchemaFactory
.builder(JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7)).jsonMapper(objectMapper).build();
.builder(JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7)).build();

schemaValidatorsConfig.setTypeLoose(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ private void setupSchema() throws IOException {
SchemaValidatorsConfig schemaValidatorsConfig = new SchemaValidatorsConfig();
JsonSchemaFactory schemaFactory = JsonSchemaFactory
.builder(JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7))
.jsonMapper(objectMapper)
.build();

schemaValidatorsConfig.setTypeLoose(false);
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/networknt/schema/Issue428Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class Issue428Test extends HTTPServiceSupport {
protected ObjectMapper mapper = new ObjectMapper();
protected JsonSchemaFactory validatorFactory = JsonSchemaFactory
.builder(JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V4)).jsonMapper(mapper).build();
.builder(JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V4)).build();

private void runTestFile(String testCaseFile) throws Exception {
final SchemaLocation testCaseFileUri = SchemaLocation.of("classpath:" + testCaseFile);
Expand Down
13 changes: 0 additions & 13 deletions src/test/java/com/networknt/schema/Issue510Test.java

This file was deleted.

1 change: 0 additions & 1 deletion src/test/java/com/networknt/schema/Issue928Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public class Issue928Test {
private JsonSchemaFactory factoryFor(SpecVersion.VersionFlag version) {
return JsonSchemaFactory
.builder(JsonSchemaFactory.getInstance(version))
.jsonMapper(mapper)
.schemaMappers(schemaMappers -> schemaMappers.mapPrefix("https://example.org", "classpath:"))
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class OpenAPI30JsonSchemaTest extends HTTPServiceSupport {
protected ObjectMapper mapper = new ObjectMapper();
protected JsonSchemaFactory validatorFactory = JsonSchemaFactory
.builder(JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V4)).jsonMapper(mapper).build();
.builder(JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V4)).build();

public OpenAPI30JsonSchemaTest() {
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/networknt/schema/UnknownMetaSchemaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void testSchema1() throws IOException {
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(this.json);

JsonSchemaFactory factory = JsonSchemaFactory.builder(JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7)).jsonMapper(mapper).build();
JsonSchemaFactory factory = JsonSchemaFactory.builder(JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7)).build();
JsonSchema jsonSchema = factory.getSchema(schema1);

Set<ValidationMessage> errors = jsonSchema.validate(jsonNode);
Expand All @@ -35,7 +35,7 @@ public void testSchema2() throws IOException {
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(this.json);

JsonSchemaFactory factory = JsonSchemaFactory.builder(JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7)).jsonMapper(mapper).build();
JsonSchemaFactory factory = JsonSchemaFactory.builder(JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7)).build();
JsonSchema jsonSchema = factory.getSchema(schema2);

Set<ValidationMessage> errors = jsonSchema.validate(jsonNode);
Expand All @@ -48,7 +48,7 @@ public void testSchema3() throws IOException {
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(this.json);

JsonSchemaFactory factory = JsonSchemaFactory.builder(JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7)).jsonMapper(mapper).build();
JsonSchemaFactory factory = JsonSchemaFactory.builder(JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7)).build();
JsonSchema jsonSchema = factory.getSchema(schema3);

Set<ValidationMessage> errors = jsonSchema.validate(jsonNode);
Expand Down
1 change: 0 additions & 1 deletion src/test/java/com/networknt/schema/V4JsonSchemaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ private Set<ValidationMessage> validateFailingFastSchemaFor(final String schemaF
config.setFailFast(true);
return JsonSchemaFactory
.builder(JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V4))
.jsonMapper(objectMapper)
.build()
.getSchema(schema, config)
.validate(dataFile);
Expand Down

0 comments on commit d77dacd

Please sign in to comment.