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

Unexpected "timestamp" matchingRule in json file instead of "date" #1617

Open
jan-schumacher opened this issue Oct 10, 2022 · 6 comments
Open
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@jan-schumacher
Copy link

MatchingRules.kt parses the json content unexpectedly from date to timestamp.
Since commit: 0596ce7

This process happens only if you have more than one pact on consumer side. All pacts but the last one are incorrect (The last one wont be deserialized)

For some reason there is this new "format" value that is missing on pact serialization but is required for deserialization to get the correct class type.
Same seems to be true for TimeMatcher.

It is broken between line 111 to 122
https://github.com/pact-foundation/pact-jvm/blame/0596ce7bdbf0f1984e99920514c58953565295bd/core/model/src/main/kotlin/au/com/dius/pact/core/model/matchingrules/MatchingRules.kt#L111

Expected behaviour: Time and Date types are correctly handled and deserialized, as well as serialized

@rholshausen
Copy link
Contributor

Are you able to provide an example Pact file that has this problem?

@bit-jkraushaar
Copy link

bit-jkraushaar commented Nov 14, 2022

Tested with au.com.dius.pact.core:model:4.3.16, using a V4 Pact

I think the bug occurs during serialization. According to the spec the DateMatcher should be serialized as:

{ "match": "date", "format": "yyyy-MM-dd" }

But actualy it serializes to:

{ "date": "yyyy-MM-dd", "match": "date" }

See here:

override fun toMap(spec: PactSpecVersion) = mapOf("match" to "date", "date" to format)

When the Pact file gets deserialized (e.g., to merge the existing interactions with a new interaction) and the machting rules get parsed, it expects the 'format' field to be present:

if (values.has("format")) DateMatcher(values["format"].toString())

Because of the serialization error it gets deserialized as TimestampMatcher.
Later Pact serializes the wrong matcher back to the file.

@jan-schumacher
Copy link
Author

@bit-jkraushaar Exactly thats what I observed.
@rholshausen Unfortunately I can't provide any free to use pact file

@rholshausen
Copy link
Contributor

Damn, I thought this had been fixed.

@rholshausen rholshausen added the bug Indicates an unexpected problem or unintended behavior label Dec 1, 2022
@rholshausen
Copy link
Contributor

/jira create

@github-actions
Copy link

👋 Thanks, Jira [PACT-446] ticket created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants