0

I have the following dependencies in my 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>

this is my json schema

{
    "$schema": "http://json-schema.org/draft-06/schema#",
    "id": "test",
    "title": "test-json validation",
    "description": "This schema should define the structure of the test json",
    "allOf": [
        {
            "$ref": "classpath:/jsonSchema/header/test.json#/definitions/test"
        },
        {
            "$ref": "classpath:/jsonSchema/rows/test.json#/definitions/test"
        }
    ],
    "properties": {
        "version": {
            "type": "array",
            "items": {
                "type": "string",
                "enum": [
                    "2.0",
                    "2.1"
                ]
            }
        }
    },
    "required": [
        "version"
    ]
}

and this is what I am trying to achieve

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;
    }

And I get the following exception:

SchemaException: classpath:/jsonSchema/header/order_header.json#/definitions/order_header/properties/order_header/properties/origin/properties/locale: expected type is one of Boolean or JsonObject, found: String at org.everit.json.schema.loader.LoadingState.createSchemaException(LoadingState.java:142) at org.everit.json.schema.loader.JsonValue$Multiplexer.multiplexFailure(JsonValue.java:50) at org.everit.json.schema.loader.JsonValue$Multiplexer.lambda$requireAny$1(JsonValue.java:45) at java.util.Optional.orElseThrow(Optional.java:290) at org.everit.json.schema.loader.JsonValue$Multiplexer.requireAny(JsonValue.java:45) at org.everit.json.schema.loader.SchemaLoader.load(SchemaLoader.java:434) [6x]

1 Answer 1

3

The values in a properties object must be a schema.

In your case, you've put "string" as a value.

The error you're seeing is the SCHEMA fails to validate, because it expects to see a Boolean or a JSON object, but gets a string, for the property value of locale.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.