Verify icon indicating copy to clipboard operation
Verify copied to clipboard

Add a way to include properties which are equal to their default value

Open JustASquid opened this issue 2 years ago • 3 comments

Is the feature request related to a problem

The problem is that there is currently no good way to include specific types/properties in the Verify output if they are equal to their default value. It is possible to set DefaultValueHandling = DefaultValueHandling.Include for the serializer settings at a global level, but generally this is unwanted as most properties should indeed be excluded if they are the default.

However it's quite useful for specific properties or types to be included regardless to keep the verify output uniform and clean. For example, my main use case is for numbers that might fluctuate between zero and numbers close to zero. The verify properties popping in and out is problematic. In addition, we employ a value converter to round the values which allows small insignificant changes in floating point results to pass the verify tests. However, the value converter isn't even invoked when the value is zero leading to failing tests.

Describe the solution

My proposed solution is to add a new value to the ScrubOrIgnore enum called AlwaysInclude or similar which will force the property to be included by the serializer even if it is the default value. See #1141

Describe alternatives considered

One alternative is to make the CustomContractResolver public so it could be subclassed. This is a simpler change but leaves the burden of functionality on the library user, and also creates a new public-facing interface. I'd be satisfied with this change if the suggested solution isn't acceptable.

JustASquid avatar Feb 07 '24 00:02 JustASquid

Hey @SimonCropp - just wondering if you've had a chance to look at the PR @JustASquid raised here as a solution to this issue as we'd like to use this in a current solution.

simonpinn avatar Feb 27 '24 23:02 simonpinn

@simonpinn sorry for the delayed response. yes the PR submitted by @JustASquid is ok. just needs some docs

SimonCropp avatar Feb 28 '24 07:02 SimonCropp

No need to apologise @SimonCropp - greatly appreciate the reply, @JustASquid adding docs 👍

simonpinn avatar Feb 28 '24 21:02 simonpinn