Hi team, I am getting the following error while tr...
# pact-jvm
h
Hi team, I am getting the following error while trying to use this array matcher in the consumer test :- `JSON parse error: Cannot deserialize value of type
java.lang.String
from Array value (token
JsonToken.START_ARRAY
)`
"sample": [
"sample1",
"sample2"
],
u
Why have you got maxArrayLike inside another array?
h
It is just one of the tries to get it working!
because
eachLike("sample")
does not seem to work
u
Is this not what you need?
Copy code
> import au.com.dius.pact.consumer.dsl.PactDslJsonBody
> 
> new PactDslJsonBody('$', "test", null)
>   .eachLike("sample", 2)
>     .stringType("name", "sample1")
>     .closeObject()
>   .closeArray()

Result: {"sample":[{"name":"sample1"},{"name":"sample1"}]}
h
👆not working at my end
the array in my case only has values, as you can see in the code that I have shared, it doesnt have a key-value pair inside
sample
u
Copy code
> import au.com.dius.pact.consumer.dsl.PactDslJsonBody
> import au.com.dius.pact.consumer.dsl.PactDslJsonRootValue
> 
> new PactDslJsonBody('$', "test", null)
>   .eachLike("sample", PactDslJsonRootValue.stringType("sample1"), 2)

Result: {"sample":["sample1","sample1"]}
h
@uglyog this one worked, thank you🙏! what if we dont want to specify the number of values , since the response is dynamic?
u
eachLike uses a fixed number of values in the consumer test, but can match any number of values
h
okay got it, thank you for saving the day🙏
👍 2
@uglyog getting another issue now, since there is an array of objects just above this array, which I am trying to validate and I am getting this error Do I need to use
.object()
here?
u
Missing bracket
h
added, but the error is still here
its working now, placed it above the array of objects, thanks!