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.

Automatically create a `PactDslJsonBody` from a Java object

See original GitHub issue

Currently, to define the body of a message within a Java consumer test, we have to do the following:

new PactDslJsonBody()
  .stringType("firstName", "Zaphod")
  .stringType("lastName", "Beeblebrox"))
  .toPact();

This is quite cumbersome, especially for large objects (which are not unusual).

Is there a way to automatically create a PactDslJsonBody from a given Java object?

If not, consider this a feature request 😃.

Implementing a mapper that does this seems easy enough, and I’d gladly give it a try.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
uglyogcommented, May 22, 2018

Should be able to do this.

1reaction
schuetteccommented, Aug 30, 2019

We build a lib for that. It creates calls on PactDslJsonBody from a Java Bean. Matcher are used by default. But you can configure it very flexible. @thombergs https://github.com/remondis-it/pact-consumer-builder 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Automatically create a `PactDslJsonBody` from a Java object
Currently, to define the body of a message within a Java consumer test, we have to do the following: new PactDslJsonBody() .
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 >
How to generate dynamic PactDslJsonBody using json value?
It is technically possible to auto-generate the DSL classes from a JSON document, but I do not see the benefit of your example....
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 ... that and only allow you to paste...
Read more >
How to fetch the data from Nested JSON Object using ...
This blog will have to help you fetch the data from nested JSON Object using a PactDslJsonBody. How to parse nested JSON in...
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