json-path/JsonPath · error · JsonPathException
Gson not found on path
Error message
Gson not found on path
What it means
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.
Source
Thrown at json-path/src/main/java/com/jayway/jsonpath/spi/mapper/GsonMappingProvider.java:59
}
public GsonMappingProvider(Callable<Gson> factory) {
this.factory = factory;
}
public GsonMappingProvider() {
super();
try {
Class.forName("com.google.gson.Gson");
this.factory = new Callable<Gson>() {
@Override
public Gson call() {
return new Gson();
}
};
} catch (ClassNotFoundException e) {
logger.error("Gson not found on class path. No converters configured.");
throw new JsonPathException("Gson not found on path", e);
}
}
@Override
public <T> T map(Object source, Class<T> targetType, Configuration configuration) {
if(source == null){
return null;
}
try {
return factory.call().getAdapter(targetType).fromJsonTree((JsonElement) source);
} catch (Exception e){
throw new MappingException(e);
}
}
@Override
public <T> T map(Object source, TypeRef<T> targetType, Configuration configuration) {
if(source == null){View on GitHub (pinned to 62a4c9f0f6)
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
Example fix
// before (build.gradle)
dependencies { implementation 'com.jayway.jsonpath:json-path:2.9.0' }
// after
dependencies {
implementation 'com.jayway.jsonpath:json-path:2.9.0'
implementation 'com.google.code.gson:gson:2.10.1'
} Defensive patterns
Strategy: validation
Validate before calling
try {
Class.forName("com.google.gson.Gson");
} catch (ClassNotFoundException e) {
throw new IllegalStateException("Add com.google.code.gson:gson to the classpath before using GsonMappingProvider");
} Try / catch
try {
Configuration conf = Configuration.builder().mappingProvider(new GsonMappingProvider()).build();
} catch (JsonPathException e) {
// Gson missing — fall back to Jackson or JsonSmart mapping provider
conf = Configuration.defaultConfiguration();
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.
Related errors
- Criteria can not be null
- Could not parse criteria
- Criteria build exception. Complete on criteria before defini
- Options AS_PATH_LIST and ALWAYS_RETURN_LIST are not allowed
- No type info in TypeRef
AI-assisted analysis of json-path/JsonPath@62a4c9f0f6 (2026-09-11).
Data as JSON: /api/errors/aa5f7fa1a5f984f0.
Report an issue: GitHub.