Java Json模式验证失败
我的Java Json模式验证失败,java,jsonschema,json-schema-validator,Java,Jsonschema,Json Schema Validator,我的pom.xml中有以下依赖项 <!-- https://github.com/everit-org/json-schema --> <dependency> <groupId>com.github.everit-org.json-schema</groupId> <artifactId>org.everit.json.sche
pom.xml中有以下依赖项
<!-- https://github.com/everit-org/json-schema -->
<dependency>
<groupId>com.github.everit-org.json-schema</groupId>
<artifactId>org.everit.json.schema</artifactId>
<version>1.11.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>
这就是我想要实现的
public Schema createSchema(String schemaPath) throws IOException {
Schema schema = null;
try (InputStream inputStream = new ClassPathResource(schemaPath).getInputStream()) {
JSONObject rawSchema = new JSONObject(new JSONTokener(inputStream));
schema = SchemaLoader.load(rawSchema);
}
return schema;
}
我得到以下例外情况:
SchemaException:classpath:/jsonSchema/header/order_header.json#/definitions/order_header/properties/order_header/properties/properties/locale:预期类型为布尔或JsonObject之一,找到:org.everit.json.schema.loader.LoadingState.createSchemaException(LoadingState.java:142)处的字符串org.everit.json.schema.loader.JsonValue$Multiplexer.multiplexFailure(JsonValue.java:50)org.everit.json.schema.loader.JsonValue$Multiplexer.lambda$requireAny$1(JsonValue.java:45)java.util.Optional.orelsetrow(Optional.java:290)org.everit.json.schema.loader.JsonValue$Multiplexer.requireAny(JsonValue.java:45)在org.everit.json.schema.loader.SchemaLoader.load(SchemaLoader.java:434)[6x]
properties
对象中的值必须是架构
在您的例子中,您已经将“sting”
作为一个值
您看到的错误是模式无法验证,因为它希望看到布尔值或JSON对象,但得到一个字符串,对于locale
的属性值,properties
对象中的值必须是模式
在您的例子中,您已经将“sting”
作为一个值
您看到的错误是,模式无法验证,因为它希望看到布尔值或JSON对象,但获取属性值locale
的字符串
public Schema createSchema(String schemaPath) throws IOException {
Schema schema = null;
try (InputStream inputStream = new ClassPathResource(schemaPath).getInputStream()) {
JSONObject rawSchema = new JSONObject(new JSONTokener(inputStream));
schema = SchemaLoader.load(rawSchema);
}
return schema;
}