英文:
Can AssertJ traverse a JSON API response to verify the path of a node?
问题
Hamcrest库有一种非常清晰的方式来遍历JSON API响应,通过使用名为hasJsonPath
的方法来验证节点的路径。
assertThat(responseBody, hasJsonPath("$.record.book.author", equalTo("john")));
然而,我在寻找一种类似的方法来使用AssertJ查找路径并进行验证。我原以为以下类似的写法会起作用,但它无法编译通过:
assertThat(responseBody).hasJsonPath("$.record.book.author", equalTo("john"));
AssertJ是否能够遍历节点并验证其存在及其值?
英文:
Hamcrest library has a very clean way of traversing a JSON API response to verify the path of a node by using a method called hasJsonPath
assertThat(responseBody, hasJsonPath("$.record.book.author", equalTo("john")));
However, I am struggling to find a similar way to find a path and verifying it using AssertJ. I was expecting something like this would work, but it won't compile
assertThat(responseBody).hasJsonPath("$.record.book.author", equalTo("john"));
Can AssertJ traverse a node and verify its existence and its value?
答案1
得分: 3
Prefer using https://github.com/lukas-krecan/JsonUnit over generic assertions library, it has a really nice API to do what you want.
英文:
Prefer using https://github.com/lukas-krecan/JsonUnit over generic assertions library, it has a really nice API to do what you want.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论