apache/dolphinscheduler · error · RuntimeException

Object json deserialization exception.

Error message

Object json deserialization exception.

What it means

JSONUtils.toJsonString serializes an object to a JSON string with a shared Jackson ObjectMapper. Any exception during writeValueAsString is rethrown as a RuntimeException with the (misleading) fixed message 'Object json deserialization exception.' and the original cause attached. Despite the wording, this is a serialization failure, not deserialization.

Source

Thrown at dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/JSONUtils.java:306

        try {
            return objectMapper.readValue(json, type);
        } catch (Exception e) {
            throw new IllegalArgumentException("Parse json: " + json + " to type: " + type.getType() + " failed", e);
        }
    }

    /**
     * object to json string
     *
     * @param object object
     * @return json string
     */
    public static String toJsonString(Object object) {
        try {
            return objectMapper.writeValueAsString(object);
        } catch (Exception e) {
            throw new RuntimeException("Object json deserialization exception.", e);
        }
    }

    public static String toPrettyJsonString(Object object) {
        try {
            return objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(object);
        } catch (Exception e) {
            throw new RuntimeException("Object json deserialization exception.", e);
        }
    }

    /**
     * serialize to json byte
     *
     * @param obj object
     * @param <T> object type
     * @return byte array
     */

View on GitHub (pinned to 02eac45a1b)

Solutions

  1. Inspect e.getCause() to find the actual serialization failure (JsonMappingException naming the offending property).
  2. Break cycles with @JsonIgnore on the back-reference field or manage the bidirectional relation with @JsonManagedReference/@JsonBackReference.
  3. Annotate problematic getters/fields with @JsonIgnore or make the class Jackson-friendly (public getters, default constructor if it must also deserialize).
  4. For a field that legitimately fails, register a custom serializer on the shared ObjectMapper or implement JsonSerializable.
  5. As a last resort, serialize a reduced DTO containing only the needed fields instead of the whole graph.

Example fix

// before
class Node {
    private Node parent;
    private List<Node> children;
    // getters for both -> infinite recursion on toJsonString(node)
}
// after
class Node {
    @JsonIgnore
    private Node parent; // break the cycle
    private List<Node> children;
}
Defensive patterns

Strategy: try-catch

Validate before calling

// detect the most common cause (cycles) before serializing complex graphs
Set<Object> seen = Collections.newSetFromMap(new IdentityHashMap<>());
boolean cyclic = false;
for (Object o : graphNodes) { if (!seen.add(o)) { cyclic = true; break; } }

Try / catch

try {
    return JSONUtils.toJsonString(obj);
} catch (RuntimeException e) {
    logger.error("toJsonString failed for {}: {}", obj.getClass().getName(), e.getCause(), e);
    return String.valueOf(obj); // fallback to toString
}

Prevention

When it happens

Trigger: Serializing an object with cyclic references (StackOverflowError/JsonMappingException infinite recursion), Jackson-incompatible types (no getters and no visibility config, unsupported classes like InputStream/Thread), a getter that throws, or self-referencing lazy/Hibernate-proxied entities.

Common situations: Logging an object graph containing cycles (parent<->child); serializing classes whose getters compute/throw; adding a field of a non-serializable type; serializing entities with bidirectional relationships; objects carrying unserializable JDK types.

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


AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06). Data as JSON: /api/errors/d13a15d0a54be9e1. Report an issue: GitHub.