Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Add a custom number comparator to the Json Diff to trim trailing zeros #2611

Merged
merged 2 commits into from
Feb 19, 2024

Conversation

leeturner
Copy link
Contributor

@leeturner leeturner commented Feb 19, 2024

In PR 2588 we set our ObjectMapper to not normalise BigDecimal values. This fixed the undesirable behavior of values such as this - {"float": 2.0} being changed to this - {"float": 2}. This PR maintains that behaviour.

Because decimal values are no longer being normalised, this means we have an issue with the json Diff not seeing numbers like 1.2 and 1.2000 as the same values. This change adds a new NumberComparator to the Diff to normalise the BigDecimal values so we can continue to compare those values in the same way as we used to in versions prior to 3.4.0.

Submitter checklist

  • Recommended: Join WireMock Slack to get any help in #help-contributing or a project-specific channel like #wiremock-java
  • The PR request is well described and justified, including the body and the references
  • The PR title represents the desired changelog entry
  • The repository's code style is followed (see the contributing guide)
  • Test coverage that demonstrates that the change works as expected
  • For new features, there's necessary documentation in this pull request or in a subsequent PR to wiremock.org

fixes #2610

Now we have set our ObjectMapper to not normalise BigDecimal values, we
have an issue with the json Diff not seeing numbers like `1.2` and
`1.2000` as the same values. This change adds a new Normalised Number
Comparator to the Diff so we can continue to compare those values in
the same way as we used to.
@leeturner leeturner requested a review from a team as a code owner February 19, 2024 16:30
@@ -257,4 +257,21 @@ public class MappingJsonSamples {
+ " \"body\": \"国家标准\" \n"
+ " } \n"
+ "}\n";

public static final String MAPPING_REQUEST_JSON_BODY_DECIMALS_NO_TRAILING_ZEROS =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These \n were all aligned in the editor :)

@tomakehurst
Copy link
Member

Is there also a risk that this is broken for matchesJsonPath?

@leeturner
Copy link
Contributor Author

Is there also a risk that this is broken for matchesJsonPath?

I have added some tests to MatchesJsonPathPatternTest to validate we can match on decimals with and without trailing zeros. Looks like it is find

@tomakehurst tomakehurst merged commit f7aad0a into master Feb 19, 2024
7 checks passed
@tomakehurst tomakehurst deleted the 2610-matching-decimals-with-trailing-zeros branch February 19, 2024 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Decimals matching issue in wiremock 3.4.0
3 participants