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:
- JSON using Jackson 2 (Faster Jackson (databind))
- JSON using Jackson (databind)
- JSON using Gson
- 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)));
}