【问题标题】:Json path doesn't match. Expected sql.Date, found lang.String (RestAssure)Json 路径不匹配。预期 sql.Date,找到 lang.String (RestAssure)
【发布时间】:2016-06-07 07:42:44
【问题描述】:

我对响应体的反序列化有疑问。我需要 sql.Date 但实际上我得到了 lang.String 请帮助我正确设置我的 RestAssure。

这是我的RestAssure.config 的样子:

RestAssured.config =
    RestAssuredConfig.config().objectMapperConfig(objectMapperConfig()
    .gsonObjectMapperFactory((aClass, s) -> 
    new GsonBuilder().setDateFormat("yyyy-MM-dd").create()));

这是我的测试:

given() 
       .contentType("application/json") 
       .when() .get("some url") .then()
       .assertThat().body("birthday", response ->
       equalTo(Date.valueOf("2016-06-07")))

我得到了这样的例外:

java.lang.AssertionError: 
 1 expectation failed. 
 JSON path birthday doesn't match. 
 Expected: <1994-12-30> Actual: 1994-12-30

【问题讨论】:

    标签: java json rest rest-assured


    【解决方案1】:

    在响应中使用extract() 以获得所需的值并将您的字符串转换为您想要的任何内容。

    Response r = given() 
       .contentType("application/json") 
       .when() .get("some url") 
       .then()
       .extract();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-07
      • 2010-09-20
      • 2017-05-28
      • 2019-02-02
      • 1970-01-01
      • 2019-08-26
      • 1970-01-01
      • 2018-09-11
      相关资源
      最近更新 更多