Last active
June 10, 2019 01:49
-
-
Save darichey/90baa0c9c8430063373967c4f0ae34da to your computer and use it in GitHub Desktop.
Justify reference issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"baz": { | |
"qux": 3 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "http://json-schema.org/draft-07/schema#", | |
"$id": "bar.schema.json", | |
"type": "object", | |
"properties": { | |
"baz": { | |
"$ref": "baz.schema.json" | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"qux": 3 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "http://json-schema.org/draft-07/schema#", | |
"$id": "bar.schema.json", | |
"type": "object", | |
"properties": { | |
"qux": { | |
"type": "integer" | |
} | |
}, | |
"required": ["qux"] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"bar": { | |
"baz": { | |
"qux": 3 | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "http://json-schema.org/draft-07/schema#", | |
"$id": "foo.schema.json", | |
"type": "object", | |
"properties": { | |
"bar": { | |
"$ref": "bar.schema.json" | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.leadpony.justify.api.*; | |
import javax.json.JsonReader; | |
import javax.json.JsonValue; | |
import java.nio.file.Path; | |
import java.nio.file.Paths; | |
public class Test { | |
public static void main(String[] args) { | |
test("baz"); | |
test("bar"); | |
test("foo"); | |
} | |
private static final JsonValidationService service = JsonValidationService.newInstance(); | |
private static void test(String name) { | |
JsonSchema schema = readSchema(Paths.get("schema", name + ".schema.json")); | |
ProblemHandler problemHandler = service.createProblemPrinter(System.out::println); | |
Path instance = Paths.get("sample", name + ".json"); | |
try (JsonReader reader = service.createReader(instance, schema, problemHandler)) { | |
JsonValue value = reader.readValue(); | |
System.out.println(value); | |
} | |
} | |
private static JsonSchema readSchema(Path path) { | |
JsonSchemaReaderFactory factory = service.createSchemaReaderFactoryBuilder() | |
.withSchemaResolver(id -> service.readSchema(Paths.get("schema", id.getPath()))) | |
.build(); | |
try (JsonSchemaReader reader = factory.createSchemaReader(path)) { | |
return reader.read(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment