如何在放心中发送布尔值作为json主体



我有一个PUT服务,其中请求主体为true或false。该服务在Postman中运行良好,内容类型为application/json。但当我在Rest Assured中尝试同样的操作时,它失败了,并且我得到了一个错误,说"JSONObject文本必须以"{"开头">

下面是我的代码:

RestAssured.given()
.contentType(ContentType.JSON)
.accept(ContentType.ANY)
.body(true)
.put(sUrl)
.then().log().ifError()
.statusCode(Matchers.greaterThanOrEqualTo(200))
.statusCode(Matchers.lessThanOrEqualTo(299))
.extract()
.response();

如果您知道任何解决方案,请告诉我。

单独的基元不是有效的json,您已经通过contentType(ContentType.JSON)指定了它。

实体必须是对象/贴图或对象/贴图数组。

尝试

.body(Map.of("value", true))

最新更新