英文:
How to specify root level array, of minimal size and each object matching pattern
问题
我在 Pact 中创建 DSL 时遇到问题,该 DSL 将接受最小大小的数组,其中每个元素都与给定的对象模式相匹配。当 JSON 对象内部有数组时,我没有问题,然后我可以简单地调用:
DslPart body = new PactDslJsonBody()
.minArrayLike("users")
.id()
.stringType("name")
.closeObject()
.closeArray();
但是如果数组是根对象怎么办?我尝试了以下方式:
new PactDslJsonArray()
.minArrayLike("users")
.id()
.stringType("name")
.closeObject()
.closeArray();
但是模式与请求不符(它似乎期望数组内有一个数组,因为它抛出反序列化异常,说 '[' 字符是意外的)。
英文:
I have problems creating a DSL in pact, which will accept array of minimal size where each element matches given object pattern. I have no problems when I have an array inside a JSON object, then I can simply call:
DslPart body = new PactDslJsonBody()
.minArrayLike("users")
.id()
.stringType("name")
.closeObject()
.closeArray();
But how can I do it in case Array is the root object? I tried following:
new PactDslJsonArray()
.minArrayLike("users")
.id()
.stringType("name")
.closeObject()
.closeArray();
But the pattern does not comply with request (it looks like it expects an array inside an array, since it throws deserialization exception saying, that '[' character was unexpected).
答案1
得分: 1
我在阅读文档时一定是瞎了眼,因为文档明确说明可以使用 PactDslJsonArray 的静态接口来完成:
PactDslJsonArray.minArrayLike()
.date("clearedDate", "mm/dd/yyyy", date)
.stringType("status", "STATUS")
.decimalType("amount", 100.0)
.closeObject()
英文:
I must have been blind while reading documentation, which clearly states that one can do it using static interface of PactDslJsonArray:
PactDslJsonArray.minArrayLike()
.date("clearedDate", "mm/dd/yyyy", date)
.stringType("status", "STATUS")
.decimalType("amount", 100.0)
.closeObject()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论