javajayway

JSONParser cannot be resolved to a type when I upgrade Json-path to 2.8


I have a project, which is using jayway jsonpath

        <dependency>
            <groupId>com.jayway.jsonpath</groupId>
            <artifactId>json-path</artifactId>
            <version>2.7.0</version>
            <scope>compile</scope>
        </dependency>   

It works well.

I tried to update it to the latest version 2.8.

Then I got some weird compiling errors: JSONParser cannot be resolved to a type JSONObject cannot be resolved to a type in one Java file. While it has no problem with exact the same code in another Java file which is in test scope.

I tried it in command line and got the same issue. So, it is not IDE issue. I also checked the version conflict in maven dependency and found no conflict. This is related code:

import net.minidev.json.JSONObject;
import net.minidev.json.parser.JSONParser;
import net.minidev.json.parser.ParseException;


    public static JSONObject convertJSONStr2Obj(String jsonStr) throws FileNotFoundException, URISyntaxException, ParseException {
        JSONObject expectedJson = (JSONObject)new JSONParser(JSONParser.DEFAULT_PERMISSIVE_MODE).parse(jsonStr);
        return expectedJson;
    }

Solution

  • Finally I figure out the root cause of this issue:

    jayway jsonpath has a dependency on json-smart.

    In previous version, it is on compile scope, but the latest version the scope is changed to runtime, which means package itself doesn't include this library and compiling fails.

    But for unit test code, it has no package concept, so it can pass compiling.