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.

XmlBodyMatcher does not ignore unexpected elements

See original GitHub issue

I am using pact-jvm-provider-junit_2.12 version 3.6.9 and I have a problem when verifying the matching rules on the provider side. I have an XML as request body and response body and I am trying to verify a specific field from the response, but there is a problem when the response contains more fields than what we expect, so the child element will have a different path.

I will try to explain what happens with the below example:

Actual response: <note> <to>John</to> <from>Jane</from> <subject>Reminder</subject> <address> <firstName>John</firstName> <lastName>Doe</lastName> <street>Prince Street</street> <number>34</number> <city>Manchester</city> </address> </note>

Expected response: <note> <to>John</to> <from>Jane</from> <subject>Reminder</subject> <address> <city>Manchester</city> </address> </note>

On the consumer side I am interested just in the city field, so I have the following matching rule in my pact file: "$.note.*.address.*.city: { "matchers": [ { "match": "equality" } ], "combine": "AND" }

But the problem is that everytime it takes the first child field $.note.3.address.0.city -> Expected <firstName>John</firstName> to equal <city>Manchester</city>

I am not sure if this is an issue or it’s the expected behavior. Or is there another way to identify that element?

Thanks

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
uglyogcommented, Jun 26, 2019

I had to remove the intermediate indices (which imposed the order on the elements) to get it to match. So before the path would have been a.0.b['@year'] which now becomes a.b['@year']

1reaction
uglyogcommented, Jun 26, 2019

Not rude, just demanding 😄 3.6.10 has been released

Read more comments on GitHub >

github_iconTop Results From Across the Web

XmlBodyMatcher does not ignore unexpected elements #899
I am using pact-jvm-provider-junit_2.12 version 3.6.9 and I have a problem when verifying the matching rules on the provider side.
Read more >
How to ignore Unexpected element situation in JAXB?
Use JAXB.unmarshal () which ignores unexpected elements by default. Be careful, since it will also skip schema validation.
Read more >
Ignore unexpected element UnmarshalException
The desired functionality is that when the unmarshaller hits an element that it does not understand, it ignores it and moves on, rather...
Read more >
pact-jvm
The idea with the `Like` matchers is to setup one example that should be like all the elements in the array. It doesn't...
Read more >
Solving the JAXB “unexpected element” problem - Rolfje's blog
If you are using JAXB in a maven/java project to unmarshal an XML document and you get: javax.xml.bind.UnmarshalException: unexpected ...
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