我正在一个使用 REST 接口的开源项目中工作。为了验证(将实际响应与预期匹配)我们在 JUnit 中的其余接口,我们想使用 JSONAssert。(https://github.com/skyscreamer/JSONassert)。但是我的用法有问题。请帮助解决它。
Expected JSON:
{
"objectId": "[^\\s]",
"protocol": "[^\\s]",
"hostName": "[^\\s]",
"port": "[^\\s]",
"commParams": "[^\\s]"
}
备注:objectId/protocol/hostName/port/commParams 可以是任何东西但不能为空
Actual JSON:
{
"objectId": "controller2",
"protocol": "ftp",
"hostName": "sdnorchestrator",
"port": "21",
"commParams": "username:tomcat, password:tomdog"
}
问题1:JSON Assert的哪个接口,我需要用哪个接口来解决上面的问题:下一个?
JSONAssert.assertEquals("Expected JSON", "Actual JSON" new CustomComparator(
JSONCompareMode.LENIENT_ORDER, new Customization(PREFIX, new RegularExpressionValueMatcher<Object>())));
问题2:这里的PREFIX应该是什么?(我试过用“ ”、“.”、“ . ”但没有成功)
也欢迎针对上述问题的任何其他建议(JSONAssert 除外)。