-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathBaseJsonSchemaValidatorTest.java
More file actions
55 lines (43 loc) · 1.96 KB
/
BaseJsonSchemaValidatorTest.java
File metadata and controls
55 lines (43 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.example;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.networknt.schema.JsonSchema;
import com.networknt.schema.JsonSchemaFactory;
import com.networknt.schema.SpecVersion;
public class BaseJsonSchemaValidatorTest {
private ObjectMapper mapper = new ObjectMapper();
protected JsonNode getJsonNodeFromClasspath(String name) throws IOException {
InputStream is1 = Thread.currentThread().getContextClassLoader()
.getResourceAsStream(name);
return mapper.readTree(is1);
}
protected JsonNode getJsonNodeFromStringContent(String content) throws IOException {
return mapper.readTree(content);
}
protected JsonNode getJsonNodeFromUrl(String url) throws IOException {
return mapper.readTree(new URL(url));
}
protected JsonSchema getJsonSchemaFromClasspath(String name) {
JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V6);
InputStream is = Thread.currentThread().getContextClassLoader()
.getResourceAsStream(name);
return factory.getSchema(is);
}
protected JsonSchema getJsonSchemaFromStringContent(String schemaContent) {
JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V6);
return factory.getSchema(schemaContent);
}
protected JsonSchema getJsonSchemaFromUrl(String uri) throws URISyntaxException {
JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V6);
return factory.getSchema(new URI(uri));
}
protected JsonSchema getJsonSchemaFromJsonNode(JsonNode jsonNode) {
JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V6);
return factory.getSchema(jsonNode);
}
}