5

I would like to compare if two jsonPath value are equal like this:

this.mockMvc.perform(get(requestURL)).andExpect(jsonPath("$.prop1", equalTo(jsonPath("$.prop2"))));

but then my test was failed. The jsonPath("$.prop1") returned the correct value I want, but jsonPath("$.prop2") returned not the value of this property, instead the classname like:

org.springframework.test.web.servlet.result.JsonPathResultMatchers@7b7aaaf6

Can anyone give me idea how can I perform the toString() method for the jsonPath()? I did try also jsonPath("$.prop2").toString() but also received the classname.

Thank you in advanced!

0

1 Answer 1

7
MvcResult result = this.mockMvc.perform(get(requestURL)).andReturn();
String response = result.getResponse().getContentAsString();

assertEquals(JsonPath.parse(response).read("$.prop1").toString(),JsonPath.parse(response).read("$.prop2").toString());

See github readme for more details.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.