apache/seatunnel · error · RuntimeException
json to map exception!
Error message
json to map exception!
What it means
JsonUtils.toMap wraps any Jackson failure (invalid JSON, JSON that is not an object, or key/value types not matching the requested K/V classes) into this RuntimeException, signaling the json string could not be deserialized into a Map.
Source
Thrown at seatunnel-common/src/main/java/org/apache/seatunnel/common/utils/JsonUtils.java:229
/**
* json to map
*
* @param json json
* @param classK classK
* @param classV classV
* @param <K> K
* @param <V> V
* @return to map
*/
public static <K, V> Map<K, V> toMap(String json, Class<K> classK, Class<V> classV) {
if (StringUtils.isEmpty(json)) {
return Collections.emptyMap();
}
try {
return OBJECT_MAPPER.readValue(json, new TypeReference<Map<K, V>>() {});
} catch (Exception e) {
throw new RuntimeException("json to map exception!", e);
}
}
/**
* json to object
*
* @param json json string
* @param type type reference
* @param <T> type
* @return return parse object
*/
public static <T> T parseObject(String json, TypeReference<T> type) {
if (StringUtils.isEmpty(json)) {
return null;
}
try {
return OBJECT_MAPPER.readValue(json, type);View on GitHub (pinned to cf67b549a7)
Solutions
- Read the chained cause: JsonParseException = invalid JSON; MismatchedInputException = shape/type mismatch
- Ensure the input is a JSON object starting with '{'
- Adjust generic types so V matches the actual JSON value types (e.g. Map<String,Object> for mixed values)
- Validate the JSON string externally (jq / an online parser) before calling
Example fix
// before Map<String, String> m = JsonUtils.toMap(mixedJson); // values contain numbers/objects // after Map<String, Object> m = JsonUtils.toMap(mixedJson);
Defensive patterns
Strategy: validation
Validate before calling
boolean isJsonObject(String s) { return s != null && s.trim().startsWith("{"); } Try / catch
try {
Map<String, Object> m = JsonUtils.toMap(json);
} catch (RuntimeException e) {
throw new IllegalStateException("cannot parse json map: " + e.getCause().getMessage(), e);
} Prevention
- Use Map<String,Object> for heterogeneous value types to avoid binding mismatches
- Validate JSON snippets with an external parser before embedding them in code
- Handle empty input before calling toMap
When it happens
Trigger: Calling JsonUtils.toMap(json) with invalid JSON, a JSON array or scalar instead of an object, or values that don't fit the K/V generic types (e.g. numbers when Map<String,String> expected).
Common situations: Parsing config snippets or webhook payloads, reading JSON written by another tool with different types, generic-type erasure surprises when K/V don't match actual JSON types.
Understand the failure class
Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.
Related errors
- Json parse object exception!
- Json parse list exception!
- Json parse object exception.
- String json deserialization exception.<content>
- Json deserialization exception.
AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10).
Data as JSON: /api/errors/cb3f64a39f84e07d.
Report an issue: GitHub.