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.

Object can be null or have value

See original GitHub issue

Hi, This is a question. What is the best way for me to define something like below in Pact Fragment -

"Certification": {
    "Java": {
        "Version": "1.7",
        "Year": "2015" 
    },
    "Scala": null,
    "C#": null,
    "C": null,
}

So basically inside Certification object, each object can be null or have some additional fields.

What would be a good way to do this so it accepts values or null?

Issue Analytics

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

github_iconTop GitHub Comments

8reactions
bengrocommented, Nov 22, 2017

This is a real shame to not support conditional parts in responses. Is there no solution/workaround to this problem still?

Given I have different types of objects:

[
  {
    type: "TYPE_A"
  },
  {
    type: "TYPE_B"
  }
]

I would like to be able to write a matcher, which only focuses on TYPE_A, hence making my matching rules conditional on the type.

Given the schema-less nature of JSON, this should definitely be supported.

5reactions
uglyogcommented, Sep 22, 2016

@alonpeer has described a elegant solution if you are able to change the format of the JSON.

As to optional values, we don’t really support them (the idea is to leave optional things out and only include the important things in the contract. Also see https://docs.pact.io/faq/#why-is-there-no-support-for-specifying-optional-attributes)

There is a specification change proposed (https://github.com/pact-foundation/pact-specification/tree/version-4#additional-matchers) to introduce an or condition with additional matchers, but it is a work in progress.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nulls in Value Objects - Enterprise Craftsmanship
Sometimes, a value object should be nullable in one entity but non-nullable in another entity. How to best handle such a use case?...
Read more >
null - JavaScript - MDN Web Docs - Mozilla
The null value represents the intentional absence of any object value. It is one of JavaScript's primitive values and is treated as falsy...
Read more >
Why is null an object and what's the difference between null ...
A property when it has no definition is undefined . a null is an object. Its type is object . null is a...
Read more >
Object can be null or have value · Issue #319 · pact ... - GitHub
Hi, This is a question. What is the best way for me to define something like below in Pact Fragment - "Certification": {...
Read more >
How to Check for an Object in Javascript (Object Null Check)
Typically, you'll check for null using the triple equality operator ( === or !== ), also known as the strict equality operator, to...
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