question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PactDslJsonBody - can not create an object without name

See original GitHub issue

I am trying to create a PactDslJsonBody instance, which matches JSON with the following form:

{
  "array": [
       {
          "id": 1,
          "description": "Some Description",
       },
       {
          "id": 2,
          "description": "Some Other Description",
       }
   ]
}

My code is something like:

PactDslJsonBody body = new PactDslJsonBody()
.minArrayLike("array", 1)
    .object() // Throws exception
        .integerType("id")
        .stringType("description") 
    .closeObject()
.closeObject().closeArray() // Close the array

The problem is that PactDslJsonBody.object always throws and exception and advises to use object(String name).

How can I create an object, without a name that will match the provided Json sample?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
uglyogcommented, Dec 21, 2017

I assume he meant this:

PactDslJsonBody body = new PactDslJsonBody()
.minArrayLike("array", 1)
    // .object() // should be removed
        .integerType("id")
        .stringType("description") 
    .closeObject()
.closeObject().closeArray() // Close the array
0reactions
uglyogcommented, Oct 17, 2020

I have not seen one. Someone once mentioned that they were going to create one (a few years ago), but I can’t recall where they got with that. A Google search turned up https://github.com/remondis-it/pact-consumer-builder, which builds it from Java objects.

Read more comments on GitHub >

github_iconTop Results From Across the Web

PactDslJsonBody - can not create an object without name #217
The problem is that PactDslJsonBody.object always throws and exception and advises to use object(String name). How can I create an object, ...
Read more >
PactDslJsonBody is failing to create JSON object
Ah, I think I see it now. You need to end new PactDslJsonBody() with closeObject() (so there's 2 in the end since you...
Read more >
Provides a DSL for use with Java to build consumer pacts.
The body method of the ConsumerPactBuilder can accept a PactDslJsonBody, which can construct a JSON body as well as define regex and type ......
Read more >
PactDslJsonBody - javadoc.io
Parameters: name - attribute name: value - string value ... Attribute that is an array of values that are not objects where each...
Read more >
Pact with Java (by example) - HMH Engineering
I've recently written an article talking a little bit about how to set up Pact tests with JUnit and REST Assured. However, it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found