Java 使用JsonPath验证返回列表的特定键的值
答复机构:Java 使用JsonPath验证返回列表的特定键的值,java,json,assertions,hamcrest,jsonpath,Java,Json,Assertions,Hamcrest,Jsonpath,答复机构: { "Items":[{ "ID": 12, "Name": "n1", "Inactive": false }, { "ID": 16, "Name": "n2", "Inactive": false }, ...etc ] } 通过使用JsonPath库,我能够使用下面
{
"Items":[{
"ID": 12,
"Name": "n1",
"Inactive": false
},
{
"ID": 16,
"Name": "n2",
"Inactive": false
}, ...etc
]
}
通过使用JsonPath库,我能够使用下面的表达式获得特定元素(比如“Inactive”)的所有值的列表。
'$.. 非活动'-->[假,假,…等]
但是,我不确定如何使用jsonpathsassert应用matcher来断言上述列表,使其只包含“false”
我正在使用Java,JsonPath。有人能帮我一下吗?经过一些研究,我能够断言这个列表——它应该只包含下面提到的“false”
org.hamcrest.MatcherAssert.assertThat(actualJson.toString(), JsonPathMatchers.hasJsonPath("$..Inactive", Matchers.everyItem(Matchers.equalTo(false))));