Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure RestAssured to use GSON over Jackson?

I have both GSON and Jackson in a project using RestAssured and I want to use GSON. The official documentation does not provide a clear example. I tried several configs, but it does not seem to work. Here's my config, am I missing something?

RestAssured.config = RestAssuredConfig.config()
                .decoderConfig(new DecoderConfig("UTF-8"))
                .encoderConfig(new EncoderConfig("UTF-8", "UTF-8"))
                .objectMapperConfig(new ObjectMapperConfig(GSON));
like image 387
vicusbass Avatar asked Mar 29 '18 09:03

vicusbass


2 Answers

In my project I solved it by wrapping original RestAssured.given method

public static RequestSpecification given() {
    return RestAssured.given()
        .config(RestAssured.config()
            .objectMapperConfig(new ObjectMapperConfig(ObjectMapperType.GSON)));
}
like image 66
Maciej Mikosik Avatar answered Oct 10 '22 22:10

Maciej Mikosik


This worked for me in Kotlin:

RestAssured.config = RestAssuredConfig.config().objectMapperConfig(objectMapperConfig().defaultObjectMapperType(ObjectMapperType.GSON))

like image 29
Andre Barrett Avatar answered Oct 10 '22 21:10

Andre Barrett