-
Notifications
You must be signed in to change notification settings - Fork 38.5k
XpathExpectationsHelper should support Hamcrest matching against typed objects [SPR-14722] #19287
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
Comments
Rossen Stoyanchev commented XPath returns basic data types as well as |
Manuel Jordan commented Sounds great About:
I had the problem with JAXB2 that it does not support generic collections. I must use Jackson for XML instead, the 'drawback' is that once used Jackson through a mandatory special module required for xml, the Jaxb2 annotations are ignored. I am sharing this because because Spring 5 should work with Java 9, and I don't if the API for Jaxb2 would be changed or Jaxb 3 would be created... |
Rossen Stoyanchev commented Regarding JAXB2 and generic collections have you seen the |
Manuel Jordan commented The special module is Now the problem is the following bug: XML Empty tag to Empty string in the object during xml deserialization Practically reflected in: Spring Rest & Jackson: Empty values are transformed in Null values in XML transformation How you can see Jaxb2 and Jackson have each one its own 'situations' |
Manuel Jordan commented About Not sure If I have reported through JIRA or Stackoverflow (I think the former) this situation and from either of them |
Rossen Stoyanchev commented I don't mean using the converter directly but doing something like what it does and iterate over a NodeList. |
Revisiting this issue, there are some things I overlooked. In order to compare to a higher level object, you need to specify a target class, so it should be this at least: .andExpect(jsonPath("$", is(persona), Persona.class)) Even then, unless JSONPath is configured with a This is why I don't think we can do much more here. That said, I do actually have an alternative to suggest. If the goal is to compare higher level objects, you can use @Test
void xml() {
MockMvcWebTestClient.bindToController(new PersonController()).build()
.get()
.uri("/person/Lee")
.accept(MediaType.APPLICATION_XML)
.exchange()
.expectStatus().isOk()
.expectHeader().contentType(MediaType.APPLICATION_XML)
.expectBody(Person.class)
.isEqualTo(person);
} |
Uh oh!
There was an error while loading. Please reload this page.
Manuel Jordan opened SPR-14722 and commented
I am working with:
4.3.2
About
Spring MVC Test
for Json I have the following:now consider a more complex object, either more fields or relation with other objects.
With the following I have a considerable reduction of code
Same thought for collections of data returned in JSON format. Here
jsonPath
works in peace withHamcrest
The problem is with XML. I have the following:
The code works or pass, but again consider a more complex object, either more fields or relation with other objects. Sadly
xpath
does not work withHamcrest
. So I am not able to do a reduction of code. Same problem for collections of data returned in XML format.This problem has been discussed in some way in:
SPR-13687 - Why MockMvcResultMatchers has not a xpath method with org.hamcrest.Matcher?
Pls. read the latest comment
Considering that Spring Framework 5 is coming, perhaps would have sense in re-consider in apply this improvement?
Thanks by your understanding.
Affects: 4.3 GA, 4.3.1, 4.3.2, 5.0 M1
Issue Links:
Backported to: Contributions Welcome
The text was updated successfully, but these errors were encountered: