java – 配置RestAssured在Jackson上使用GSON?

前端之家收集整理的这篇文章主要介绍了java – 配置RestAssured在Jackson上使用GSON?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我在使用RestAssured的项目中有GSON和Jackson,我想使用GSON.官方文档没有提供明确的例子.我尝试了几个配置,但似乎没有用.这是我的配置,我错过了什么?

  1. RestAssured.config = RestAssuredConfig.config()
  2. .decoderConfig(new DecoderConfig("UTF-8"))
  3. .encoderConfig(new EncoderConfig("UTF-8","UTF-8"))
  4. .objectMapperConfig(new ObjectMapperConfig(GSON));
最佳答案
在我的项目中,我通过包装原始的RestAssured.given方法解决了它

  1. public static RequestSpecification given() {
  2. return RestAssured.given()
  3. .config(RestAssured.config()
  4. .objectMapperConfig(new ObjectMapperConfig(ObjectMapperType.GSON)));
  5. }

猜你在找的Java相关文章