I am getting error when I try to execute script with rest assured framework. Please guide me to resolve the same. And I used below jars
Java version - 8
rest
The root cause of this is rest-assured *ObjectMapperFactory
package names changing, for example between versions 3.x
and 4.x
.
For anyone coming across this after the release of rest-assured 4.0.0, this problem can appear in Spring Boot projects - caused by a version mismatch between rest-assured
and its transitive dependencies on json-path
and xml-path
in the spring-boot-dependencies bom.
If you specify a dependency io.rest-assured:rest-assured:4.0.0
, you also need to explicitly include io.rest-assured:json-path:4.0.0
and io.rest-assured:xml-path:4.0.0
, otherwise spring-boot-dependencies will pull in version 3.1.1
with the old *ObjectMapperFactory package names.
For anyone running into this I found this git page helpful as well : https://github.com/rest-assured/rest-assured/issues/1168
And an example of my maven POM that ended up working is this :
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>${io-rest-assured.version}</version>
<scope>test</scope>
</dependency>
<!--Added required depeendencies due to : https://github.com/rest-assured/rest-assured/issues/1168 -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured-common</artifactId>
<version>${io-rest-assured.version}</version>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>json-path</artifactId>
<version>${io-rest-assured.version}</version>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>xml-path</artifactId>
<version>${io-rest-assured.version}</version>
</dependency>
In looking at the error, You need to put GSON in your classpath or POM dependancy section explicitly since it's an optional dependency to Rest Assured.
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.1</version>
</dependency>
Another options is to define dependency on rest-assured-all
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured-all</artifactId>
<version>4.3.1</version>
<scope>test</scope>
</dependency>
And exclude 3.X version if you are using Spring Mock MVC
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>spring-mock-mvc</artifactId>
<version>3.3.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>rest-assured</artifactId>
<groupId>io.rest-assured</groupId>
</exclusion>
</exclusions>
</dependency>
As Jim Riordan said you have to explicitly include io.rest-assured:json-path:4.0.0
and io.rest-assured:xml-path:4.0.0
I also needed to add an exclusion in my maven dependency io.rest-assured:spring-mock-mvc
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>spring-mock-mvc</artifactId>
<version>4.0.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>rest-assured</artifactId>
<groupId>io.rest-assured</groupId>
</exclusion>
</exclusions>
</dependency>