view raw
daniele daniele - 6 months ago 77
JSON Question

JsonPath JUnit escape character for dots

I have a json field which is called and I am writing a unit test that checks if that field is present in the reply from the server but I can't find an escape for the dots in the name of the field.
The code of my test is :

public void testEmailTemplates() throws Exception {




But I get the following exception, because the dots are interpreted like paths:

java.lang.AssertionError: No value for JSON path: $, exception: invalid path
at org.springframework.test.util.JsonPathExpectationsHelper.evaluateJsonPath(
at org.springframework.test.util.JsonPathExpectationsHelper.exists(
at org.springframework.test.web.servlet.result.JsonPathResultMatchers$3.match(
at org.springframework.test.web.servlet.MockMvc$1.andExpect(

Do you know any escape character for the jsonPath?


It seems it is a bug in jsonPath. I've looked to the source code and it seems it doesn't have possibility to escape characters in path. The problem is in PathTokenizer's splitPath method.