Configure RestAssured to use GSON over Jackson?

This worked for me in Kotlin:

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


Well, as the Rest Assured documentation states, the order of technologies is:

  1. JSON using Jackson 2 (Faster Jackson (databind))
  2. JSON using Jackson (databind)
  3. JSON using Gson
  4. XML using JAXB

Furthermore the use of an explicit serializer or deserializer is also described.

Serialization:

Message message = new Message();
message.setMessage("My messagee");
given().
   body(message, ObjectMapperType.GSON).
when().
  post("/message");

Deserialization:

Message message = get("/message").as(Message.class, ObjectMapperType.GSON);

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