Spring 如何在MockMvc中从jsonPath()检索字符串

Spring 如何在MockMvc中从jsonPath()检索字符串,spring,mocking,jsonpath,Spring,Mocking,Jsonpath,我想比较两个jsonPath值是否相等,如下所示: this.mockMvc.perform(get(requestURL)).andExpect(jsonPath("$.prop1", equalTo(jsonPath("$.prop2")))); 但后来我的测试失败了。jsonPath(“$.prop1”)返回了我想要的正确值,但是jsonPath(“$.prop2”)没有返回此属性的值,而是返回类名,如: org.springframework.test.web.servlet.resu

我想比较两个jsonPath值是否相等,如下所示:

this.mockMvc.perform(get(requestURL)).andExpect(jsonPath("$.prop1", equalTo(jsonPath("$.prop2"))));
但后来我的测试失败了。jsonPath(“$.prop1”)返回了我想要的正确值,但是jsonPath(“$.prop2”)没有返回此属性的值,而是返回类名,如:

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

有人能告诉我如何为jsonPath()执行toString()方法吗?我也尝试了jsonPath($.prop2”).toString(),但也收到了类名

提前谢谢你

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());
有关更多详细信息,请参阅