Search code examples
rest-assuredjson-schema-validatorweb-api-testing

Getting 'NoClassDefFoundError' (com/../JsonSchemaFactory) when trying to validate schema in Rest-Assured tool


We are trying to validate a JSON response to see if it matches a schema placed in the Eclipse ClassPath. This is designed to be a Maven project and I believe we have all the dependencies in place. But we are always getting the following error:

java.lang.NoClassDefFoundError: com/github/fge/jsonschema/main/JsonSchemaFactory
    at com.jayway.restassured.module.jsv.JsonSchemaValidatorSettings.<init>(JsonSchemaValidatorSettings.java:58)
    at com.jayway.restassured.module.jsv.JsonSchemaValidator$JsonSchemaValidatorFactory.createSettings(JsonSchemaValidator.java:277)
    at com.jayway.restassured.module.jsv.JsonSchemaValidator$JsonSchemaValidatorFactory.create(JsonSchemaValidator.java:289)
    at com.jayway.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchema(JsonSchemaValidator.java:166)
    at com.jayway.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchemaInClasspath(JsonSchemaValidator.java:117)
    at com.macys.xapi.ProductServices.TestProductServices.ohGodImDoomed(TestProductServices.java:76)
Caused by: java.lang.ClassNotFoundException: com.github.fge.jsonschema.main.JsonSchemaFactory
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)

We have the following dependencies in place:

        <dependency>
            <groupId>com.jayway.restassured</groupId>
            <artifactId>rest-assured</artifactId>
            <version>2.9.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.jayway.restassured</groupId>
            <artifactId>json-schema-validator</artifactId>
            <version>2.9.0</version>
        </dependency>
        <dependency>
            <groupId>com.github.fge</groupId>
            <artifactId>jackson-coreutils</artifactId>
            <version>1.8</version>
        </dependency>
        <dependency>
            <groupId>com.github.fge</groupId>
            <artifactId>json-schema-core</artifactId>
            <version>1.2.5</version>
        </dependency>

Not sure what we are missing here - can someone please help?


Solution

  • Vishnu, Just add following dependencies and remove all above dependencies.

     <dependency>
        <groupId>io.rest-assured</groupId>
        <artifactId>rest-assured</artifactId>
        <version>3.0.1</version>
    </dependency>
    
    
     <dependency>
        <groupId>io.rest-assured</groupId>
        <artifactId>json-schema-validator</artifactId>
        <version>3.0.1</version>
    </dependency>