I not able to use the PACT DSL .closeObject()
to format a PACT interaction response. I'm asking for suggestions to make this work or asking if .closeObject()
is not working as intended? I have a Shopping cart with 2 items. When I try to format the expected response, with 2 items, using .closeObject()
, it will not compile, see code below. The compile error is on the first .closeObject()
, after ".stringMatcher("name","iPhone")
line. I need to create a hierarchy of shoppingCartItems
, in the PACT files expected response. The advertised usage of PACT DSL .closeObject()
, can be found from this link, in the "matching any key in a map section" PACT DSL examples of using .closeObject()
private DslPart respSc6() {
DslPart body = new PactDslJsonBody()
.stringMatcher("id", "ShoppingCart_[0-9]*", "ShoppingCart_0")
.eachLike("shoppingCartItem")
.numberValue("quantity", 1)
.stringMatcher("state","new")
.object("productOffering")
.stringMatcher("id","IPHONE_7")
.stringMatcher("name","iPhone")
.closeObject()
.numberValue("quantity", 5)
.stringMatcher("state","new")
.object("productOffering")
.stringMatcher("id","SMSG_GLXY_S8")
.stringMatcher("name","Samsung_Galaxy_S8")
.closeObject()
.closeObject()
.closeArray();
return body;
}
The expected JSON response payload, should look like Expected PACT response payload with hierarchical data