0

I am getting below error while checking the output of my junit, it seems there is something wrong with JSON path provided with spring.

java.lang.NoSuchMethodError: com.jayway.jsonpath.JsonPath.compile(Ljava/lang/String;[Lcom/jayway/jsonpath/Filter;)Lcom/jayway/jsonpath/JsonPath;
at org.springframework.test.util.JsonPathExpectationsHelper.<init>(JsonPathExpectationsHelper.java:53)
at org.springframework.test.web.servlet.result.JsonPathResultMatchers.<init>(JsonPathResultMatchers.java:43)
at org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath(MockMvcResultMatchers.java:133)
at com.name.registration.test.ServerConnectionTest.testLogin_Simple(ServerConnectionTest.java:20)

Junit code

callApi(C.login, input)
    .andExpect(jsonPath("$.success").value(true));
Bhavesh
  • 882
  • 2
  • 9
  • 18
  • 2
    This type of error stack is generally produced due to the version conflict. Check if you have multiple versions of this library present in your classpath. – user2004685 Apr 09 '16 at 10:24
  • I have done a static import of jsonpath => import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; – Bhavesh Apr 09 '16 at 10:28
  • 1
    Yes, but this kind of error has nothing to do with static imports. This type of error stack is generally produced due to the version conflict. Check if you have multiple versions of this library present in your classpath. – JB Nizet Apr 09 '16 at 10:53
  • Will it have any effect if .m2 repo contains multiple versions because of other projects? – Bhavesh Apr 09 '16 at 11:06

1 Answers1

1

Try giving your json-path jar a higher import order, as it may be using an older version brought in through spring or some thing else. If this is a maven project the order is taken as the order specified in the pom so I would just try moving the json-path as the first dependency. If it is currently a transitive dependency I would try explicitly specifying it as a direct dependency (again at the top).

If it is not a maven project, you can also order the dependencies in your IDE. (in Eclipse: Java build path > Order and Export.)

Joe M
  • 2,527
  • 1
  • 25
  • 25