apache/dolphinscheduler · error · IllegalArgumentException
Object: + obj + to json serialization exception.
Error message
Object: + obj + to json serialization exception.
What it means
JSONUtils.toJsonByteArray converts an arbitrary Java object to a UTF-8 JSON byte array. Any exception thrown by the underlying Jackson serialization (via toJsonString/objectMapper) is wrapped in an IllegalArgumentException whose message echoes the offending object. It signals the object graph is not JSON-serializable rather than a caller input-format problem.
Source
Thrown at dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/JSONUtils.java:332
throw new RuntimeException("Object json deserialization exception.", e);
}
}
/**
* serialize to json byte
*
* @param obj object
* @param <T> object type
* @return byte array
*/
public static <T> byte[] toJsonByteArray(T obj) {
if (obj == null) {
return null;
}
try {
return toJsonString(obj).getBytes(UTF_8);
} catch (Exception e) {
throw new IllegalArgumentException("Object: " + obj + " to json serialization exception.", e);
}
}
public static ObjectNode parseObject(String text) {
try {
if (StringUtils.isEmpty(text)) {
return parseObject(text, ObjectNode.class);
} else {
return (ObjectNode) objectMapper.readTree(text);
}
} catch (Exception e) {
throw new RuntimeException("String json deserialization exception.", e);
}
}
public static ArrayNode parseArray(String text) {
try {View on GitHub (pinned to 02eac45a1b)
Solutions
- Print/inspect the wrapped cause (e.getCause()) to find the exact failing property or type
- Annotate unserializable fields with @JsonIgnore or mark them transient and add getters Jackson can see
- Break cyclic references with @JsonManagedReference/@JsonBackReference or set SerializationFeature.FAIL_ON_SELF_REFERENCES appropriately
- Register a custom JsonSerializer/Module for third-party types that Jackson cannot handle
- Ensure the object is a plain POJO (no-arg constructor + getters) or convert it to a Map before serializing
Example fix
// before byte[] data = JSONUtils.toJsonByteArray(taskExecutionContext.getInjectedStream()); // after @JsonIgnore private transient InputStream rawStream; // exclude non-serializable field
Defensive patterns
Strategy: try-catch
Validate before calling
if (obj == null) return null; // also ensure fields are Jackson-friendly: no cycles, no raw streams
Type guard
boolean isSerializable(Object o) {
try { JSONUtils.toJsonString(o); return true; } catch (Exception e) { return false; }
} Try / catch
try {
byte[] data = JSONUtils.toJsonByteArray(obj);
} catch (IllegalArgumentException e) {
log.error("Unserializable object of type {}: {}", obj.getClass().getName(), e.getCause());
throw new IllegalStateException("Object not serializable to JSON", e);
} Prevention
- Keep DTOs as plain POJOs with getters and no cycles
- Annotate third-party or transient fields with @JsonIgnore
- Unit-test serialization of every object stored in task parameters
- Never put open resources (streams, connections) into serialized contexts
When it happens
Trigger: Calling JSONUtils.toJsonByteArray(obj) when Jackson fails on the object: no accessible getters/fields, infinite recursion from cyclic references, unserializable types (InputStream, Thread), a property getter that throws, or invalid ObjectMapper configuration
Common situations: Putting a non-POJO (e.g. an Hadoop Configuration, a lambda, an open stream) into a task parameter or workflow context that is later serialized to JSON; adding a getter with side effects or a self-referencing object graph after a version upgrade.
Understand the failure class
Background: "JSON serialization failed", "not JSON serializable", "Failed to serialize": why JSON marshaling errors happen and how to fix them — this error's family across 46 libraries.
Related errors
- Object json deserialization exception.
- Class type cannot be null
- Parse json: <json> to class: <clazz> failed
- String json deserialization exception.
- Json deserialization exception.
AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06).
Data as JSON: /api/errors/7aa20e3ad42ec548.
Report an issue: GitHub.