Search in sources :

Example 1 with GsonObjectMapperFactory

use of io.restassured.mapper.factory.GsonObjectMapperFactory in project rest-assured by rest-assured.

the class CustomObjectMappingITest method using_custom_object_mapper_factory.

@Test
public void using_custom_object_mapper_factory() {
    final Greeting greeting = new Greeting();
    greeting.setFirstName("John");
    greeting.setLastName("Doe");
    RestAssured.config = RestAssuredConfig.config().objectMapperConfig(objectMapperConfig().gsonObjectMapperFactory(new GsonObjectMapperFactory() {

        public Gson create(Type cls, String charset) {
            return new GsonBuilder().setFieldNamingPolicy(LOWER_CASE_WITH_UNDERSCORES).create();
        }
    }));
    final Greeting returnedGreeting = given().contentType("application/json").body(greeting, GSON).expect().body("first_name", equalTo("John")).when().post("/reflect").as(Greeting.class, GSON);
    assertThat(returnedGreeting.getFirstName(), equalTo("John"));
    assertThat(returnedGreeting.getLastName(), equalTo("Doe"));
}
Also used : Greeting(io.restassured.itest.java.objects.Greeting) Type(java.lang.reflect.Type) GsonObjectMapperFactory(io.restassured.mapper.factory.GsonObjectMapperFactory) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) Test(org.junit.Test)

Aggregations

Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 Greeting (io.restassured.itest.java.objects.Greeting)1 GsonObjectMapperFactory (io.restassured.mapper.factory.GsonObjectMapperFactory)1 Type (java.lang.reflect.Type)1 Test (org.junit.Test)1