Search code examples
javajsongradlejsonpath

Cannot resolve method 'read' in 'JsonPath'


I currently have a gradle project where I have a line implementation "com.jayway.jsonpath:json-path:2.4.0" in my build.gradle file. In my code, I have an import statement import org.springframework.data.web.JsonPath;, but when I actually use the JsonPath e.g. obj.put("key", JsonPath.read(jsonStr, "key1.key2.key3.key4"));, the read method appears as red in my IDE saying that it "Cannot resolve method 'read' in 'JsonPath'". I have tried refreshing gradle dependencies and closing/opening the IDE/window but nothing works - any thoughts?


Solution

  • remove this

    import org.springframework.data.web.JsonPath;
    

    use this

    import com.jayway.jsonpath.JsonPath;
    

    Read this documentation to know more about available methods.

    Hope this helps.