I have a json field called template.welcome.email and I write a unit test that checks to see if this field is present in the response from the server, but I cannot find the escape for the points in the field name. My test code:
@Test public void testEmailTemplates() throws Exception { mockMvc.perform(get("/emailTemplates") .contentType(MediaType.APPLICATION_JSON) .locale(Locale.UK) .accept(MediaType.APPLICATION_JSON)) .andDo(print()) .andExpect(status().isOk()) .andExpect(jsonPath("$.template.welcome.email").exists()) .andExpect(redirectedUrl(null)) .andExpect(forwardedUrl(null)); }
But I get the following exception because the points are interpreted as paths:
java.lang.AssertionError: No value for JSON path: $.template.welcome.email, exception: invalid path at org.springframework.test.util.JsonPathExpectationsHelper.evaluateJsonPath(JsonPathExpectationsHelper.java:74) at org.springframework.test.util.JsonPathExpectationsHelper.exists(JsonPathExpectationsHelper.java:121) at org.springframework.test.web.servlet.result.JsonPathResultMatchers$3.match(JsonPathResultMatchers.java:77) at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:141) at
Do you know any escape character for jsonPath?
java json spring spring-mvc junit
daniele
source share