github.com/phrase/openapi@v0.0.0-20240514140800-49e8a106740e/openapi-generator/templates/java/libraries/rest-assured/GsonObjectMapper.mustache (about)

     1  {{>licenseInfo}}
     2  
     3  package {{invokerPackage}};
     4  
     5  import io.restassured.mapper.ObjectMapper;
     6  import io.restassured.mapper.ObjectMapperDeserializationContext;
     7  import io.restassured.mapper.ObjectMapperSerializationContext;
     8  
     9  public class GsonObjectMapper implements ObjectMapper {
    10  
    11      private JSON json;
    12  
    13      private GsonObjectMapper() {
    14          this.json = new JSON();
    15      }
    16  
    17      public static GsonObjectMapper gson() {
    18          return new GsonObjectMapper();
    19      }
    20  
    21      @Override
    22      public Object deserialize(ObjectMapperDeserializationContext context) {
    23          return json.deserialize(context.getDataToDeserialize().asString(), context.getType());
    24      }
    25  
    26      @Override
    27      public Object serialize(ObjectMapperSerializationContext context) {
    28          return json.serialize(context.getObjectToSerialize());
    29      }
    30  }