Hi again. I’ve got another query. We’ve got a key ...
# pact-jvm
a
Hi again. I’ve got another query. We’ve got a key
blah
of type array inside an array of objects in the response body on an API like so:
Copy code
[
    {
        "id": "10bc2494-610c-4606-b169-0c33014757e9",
        "blah": [
            "testing 123",
            "Testing, testing, 123..."
        ],
        "type": "GENERIC"
    }
]
While I can use:
Copy code
DslPart dslPart = PactDslJsonArray.arrayEachLike()
                .array("blah") // Undocumented at <https://docs.pact.io/implementation_guides/jvm/consumer/junit#building-json-bodies-with-pactdsljsonbody-dsl>
                .closeArray()
        .closeObject()
to validate the key
blah
to be an array, I can’t seem to find a way to restrict the elements of the array to be of type String. Is this possible using the DSL? I’m using
au.com.dius.pact.consumer:junit:4.2.20
.
r
use
eachLike
that takes a
PactDslJsonRootValue
parameter
i.e. ``eachLike(PactDslJsonRootValue.stringType("example string value"))``
a
Thanks! I ended up using
.array("blah").stringType("testing 123").closeArray()
, which luckily works too.
Forgot to mention, here’s the source (different from what the library I’m using): https://docs.pact.io/implementation_guides/jvm/consumer