{"record":{"id":"aa5f7fa1a5f984f0","repo":"json-path/JsonPath","slug":"gson-not-found-on-path","errorCode":null,"errorMessage":"Gson not found on path","messagePattern":"Gson not found on path","errorType":"exception","errorClass":"JsonPathException","httpStatus":null,"severity":"error","filePath":"json-path/src/main/java/com/jayway/jsonpath/spi/mapper/GsonMappingProvider.java","lineNumber":59,"sourceCode":"    }\n\n    public GsonMappingProvider(Callable<Gson> factory) {\n        this.factory = factory;\n    }\n\n    public GsonMappingProvider() {\n        super();\n        try {\n            Class.forName(\"com.google.gson.Gson\");\n            this.factory = new Callable<Gson>() {\n                @Override\n                public Gson call() {\n                    return new Gson();\n                }\n            };\n        } catch (ClassNotFoundException e) {\n            logger.error(\"Gson not found on class path. No converters configured.\");\n            throw new JsonPathException(\"Gson not found on path\", e);\n        }\n    }\n\n    @Override\n    public <T> T map(Object source, Class<T> targetType, Configuration configuration) {\n        if(source == null){\n            return null;\n        }\n        try {\n            return factory.call().getAdapter(targetType).fromJsonTree((JsonElement) source);\n        } catch (Exception e){\n            throw new MappingException(e);\n        }\n    }\n\n    @Override\n    public <T> T map(Object source, TypeRef<T> targetType, Configuration configuration) {\n        if(source == null){","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/json-path/JsonPath/blob/62a4c9f0f65ba3f625aa0867d64c528ba72d09ec/json-path/src/main/java/com/jayway/jsonpath/spi/mapper/GsonMappingProvider.java#L41-L77","documentation":"GsonMappingProvider's constructor uses a Callable that loads Gson via Class.forName-style instantiation; if com.google.gson.Gson is not on the classpath it logs \"Gson not found on class path\" and rethrows JsonPathException. The provider cannot work at all without the Gson dependency, so initialization fails eagerly.","triggerScenarios":"Instantiating GsonMappingProvider (directly or by registering it as the MappingProvider in Configuration) in a project whose build does not include com.google.code.gson:gson.","commonSituations":"Adding gson support config copied from docs without adding the dependency; shading/excluding gson in a fat jar; runtime environments (app servers, Android) that strip optional deps; switching from JacksonSmart/Jackson provider to Gson provider.","solutions":["Add the Gson dependency, e.g. Maven: <dependency><groupId>com.google.code.gson</groupId><artifactId>gson</artifactId></dependency> or Gradle: implementation 'com.google.code.gson:gson:2.10.1'","Verify the jar is actually packaged (mvn dependency:tree / check the fat jar contents)","If Gson is not wanted, use a different MappingProvider (JacksonMappingProvider, JsonSmartMappingProvider) instead","Check for version exclusions or provided-scope on gson in your build"],"exampleFix":"// before (build.gradle)\ndependencies { implementation 'com.jayway.jsonpath:json-path:2.9.0' }\n// after\ndependencies {\n    implementation 'com.jayway.jsonpath:json-path:2.9.0'\n    implementation 'com.google.code.gson:gson:2.10.1'\n}","handlingStrategy":"validation","validationCode":"try {\n    Class.forName(\"com.google.gson.Gson\");\n} catch (ClassNotFoundException e) {\n    throw new IllegalStateException(\"Add com.google.code.gson:gson to the classpath before using GsonMappingProvider\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    Configuration conf = Configuration.builder().mappingProvider(new GsonMappingProvider()).build();\n} catch (JsonPathException e) {\n    // Gson missing — fall back to Jackson or JsonSmart mapping provider\n    conf = Configuration.defaultConfiguration();\n}","preventionTips":["Declare gson as a compile dependency whenever GsonMappingProvider is registered","Run dependency:tree or check packaged jars in CI to catch stripped optional deps","Prefer JacksonMappingProvider if Gson is not already on the classpath"],"tags":["classpath","dependency","gson","jsonpath"],"backgroundTag":"missing-dependency","analyzedSha":"62a4c9f0f65ba3f625aa0867d64c528ba72d09ec","analyzedAt":"2026-09-11T11:36:00.448Z","contentChangedAt":"2026-09-11T11:36:00.448Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}