json-path/JsonPath · error · JsonException
Unknown value type " + value.getValueType()
Error message
Unknown value type " + value.getValueType()
What it means
getState() maps a JsonValue's type to a parser Event; ARRAY, OBJECT, STRING, NUMBER, TRUE, FALSE, and NULL are handled, and any other ValueType falls into the default branch throwing this JsonException. With the standard JSON-P enum this is effectively unreachable, but it guards against exotic or future JsonValue implementations.
Source
Thrown at json-path/src/main/java/com/jayway/jsonpath/spi/mapper/JakartaMappingProvider.java:565
private Event getState(JsonValue value) {
switch (value.getValueType()) {
case ARRAY:
return Event.START_ARRAY;
case OBJECT:
return Event.START_OBJECT;
case STRING:
return Event.VALUE_STRING;
case NUMBER:
return Event.VALUE_NUMBER;
case TRUE:
return Event.VALUE_TRUE;
case FALSE:
return Event.VALUE_FALSE;
case NULL:
return Event.VALUE_NULL;
default:
throw new JsonException("Unknown value type " + value.getValueType());
}
}
}
private static abstract class JsonStructureScope implements Iterator<JsonValue> {
/**
* Returns current {@link JsonValue}, that the parser is pointing on. Before
* the {@link #next()} method has been called, this returns {@code null}.
*
* @return JsonValue value object.
*/
abstract JsonValue getValue();
}
private static class JsonArrayScope extends JsonStructureScope {
private final Iterator<JsonValue> it;
private JsonValue value;
View on GitHub (pinned to 62a4c9f0f6)
Solutions
- Ensure all JsonValue instances come from the same JSON-P provider (check for multiple jsonp implementations on the classpath)
- Convert foreign/custom JsonValue wrappers into standard JsonObject/JsonArray before mapping
- Catch JsonException and inspect value.getValueType() to identify the offending implementation
Example fix
// before
JsonValue v = customLib.toJsonValue(data); // non-standard ValueType
adapter.next(); // JsonException: Unknown value type
// after
JsonValue v = Json.createObjectBuilder() // standard JSON-P API
.add("data", customLib.toJsonString(data)).build(); Defensive patterns
Strategy: validation
Validate before calling
switch (value.getValueType()) {
case ARRAY: case OBJECT: case STRING: case NUMBER:
case TRUE: case FALSE: case NULL: break;
default: throw new IllegalStateException("Non-standard JsonValue type: " + value.getValueType());
} Type guard
boolean isStandardJsonValue(JsonValue v) {
switch (v.getValueType()) {
case ARRAY: case OBJECT: case STRING: case NUMBER:
case TRUE: case FALSE: case NULL: return true;
default: return false;
}
} Try / catch
try {
mapper.map(value, typeRef, config);
} catch (JsonException e) {
// unknown ValueType: value likely from a foreign JSON-P implementation
} Prevention
- Keep a single JSON-P implementation on the classpath; check for duplicate jsonp jars
- Convert custom/third-party JsonValue wrappers to standard JsonObject/JsonArray before mapping
- Pin JSON-P provider versions in your build
When it happens
Trigger: Passing a JsonValue whose getValueType() is not one of the seven standard JSON-P types — e.g. a custom or third-party JsonValue implementation with its own ValueType, or a value from a non-standard JSON-P version.
Common situations: Custom JsonValue implementations injected into the mapping pipeline; mixing JSON-P implementations (different providers on the classpath producing foreign JsonValue instances).
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- JSON-P adapter does not support getLocation()
- Cannot create JSON iterator for " + value
- InvalidJsonException
- InvalidJsonException
- InvalidJsonException
AI-assisted analysis of json-path/JsonPath@62a4c9f0f6 (2026-09-11).
Data as JSON: /api/errors/7c5a1422fc1cb7d3.
Report an issue: GitHub.