Object can be null or have value
See original GitHub issueHi, 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:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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:
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.
@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.