如何使用io.rest-assured更新json

时间:2018-12-02 09:48:11

标签: java json rest-assured jsonpath rest-assured-jsonpath

String jsonString = " 
{
 "success": true,
 "total": 282,
 "timeTaken": 31,
 "responseCode": 200,
 "facet_count": {},
 "inferred": 
{
 "city": null,
 "locality": null,
 "cityList": null,
 "state": null
 }
}
";

问题:要将“位置”值更新为“ ABCD”

我知道如何使用com.jayway,下面是该代码

Configuration configuration = Configuration.builder()
    .jsonProvider(new JacksonJsonNodeJsonProvider())
    .mappingProvider(new JacksonMappingProvider()).build();

DocumentContext json = com.jayway.jsonpath.JsonPath.using(configuration)
    .parse(jsonString);
System.out.println(json.set("inferred.locality", "ABCD").jsonString());

但无法使用io.rest保证的3.0版。

1 个答案:

答案 0 :(得分:0)

您可以尝试将json表示为POJO,然后尝试更新值。可以直接操作字符串,但是,既不推荐也不建议。