apache/seatunnel · error · RuntimeException
Object to json exception!
Error message
Object to json exception!
What it means
JsonUtils.toJsonString(Object, SerializationFeature) serializes an object to JSON with an extra Jackson SerializationFeature. Any failure during serialization (unwritable getters, infinite recursion, invalid state) is wrapped in this RuntimeException with the cause chained.
Source
Thrown at seatunnel-common/src/main/java/org/apache/seatunnel/common/utils/JsonUtils.java:110
}
public static JsonNode readTree(InputStream obj) throws IOException {
return OBJECT_MAPPER.readTree(obj);
}
/**
* json representation of object
*
* @param object object
* @param feature feature
* @return object to json string
*/
public static String toJsonString(Object object, SerializationFeature feature) {
try {
ObjectWriter writer = OBJECT_MAPPER.writer(feature);
return writer.writeValueAsString(object);
} catch (Exception e) {
throw new RuntimeException("Object to json exception!", e);
}
}
/**
* This method deserializes the specified Json into an object of the specified class. It is not
* suitable to use if the specified class is a generic type since it will not have the generic
* type information because of the Type Erasure feature of Java. Therefore, this method should
* not be used if the desired type is a generic type. Note that this method works fine if the
* any of the fields of the specified object are generics, just the object itself should not be
* a generic type.
*
* @param json the string from which the object is to be deserialized
* @param clazz the class of T
* @param <T> T
* @return an object of type T from the string classOfT
*/
public static <T> T parseObject(String json, Class<T> clazz) {
if (StringUtils.isEmpty(json)) {View on GitHub (pinned to cf67b549a7)
Solutions
- Inspect the chained cause (getCause) for the real Jackson error, e.g. JsonMappingException 'Infinite recursion (StackOverflowError)'
- Break cycles with @JsonIgnore or Jackson annotations on the offending fields
- Ensure getters do not throw (close resources before serialization or expose copies)
- Register a module/serializer for custom types, or convert to a plain DTO before serializing
Example fix
// before
class Node { Node parent; /* cyclic */ }
JsonUtils.toJsonString(node, SerializationFeature.INDENT_OUTPUT);
// after
class Node { @JsonIgnore Node parent; }
JsonUtils.toJsonString(node, SerializationFeature.INDENT_OUTPUT); Defensive patterns
Strategy: try-catch
Try / catch
try {
String json = JsonUtils.toJsonString(obj, feature);
} catch (RuntimeException e) {
log.error("serialize failed for {}: {}", obj.getClass().getName(), e.getCause(), e);
// fall back to toString() or a safe DTO
} Prevention
- Break object cycles with @JsonIgnore/@JsonBackReference before serializing
- Never serialize objects holding live resources (connections, streams)
- Test serialization of all DTOs used for logging/persistence
When it happens
Trigger: Calling JsonUtils.toJsonString(obj, feature) when Jackson cannot serialize obj: self-referencing object graph (infinite recursion), getter throwing an exception, or an unsupported type with no serializer.
Common situations: Logging complex engine objects to JSON for debugging, serializing records with cyclic references (parent/child), passing objects with throwing getters (lazy fields already closed), upgrading Jackson and losing a custom serializer.
Understand the failure class
Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.
Related errors
- Json parse object exception!
- Json parse list exception!
- Object json deserialization exception.
- JSON_OPERATION_FAILED
- COMMON_UNSUPPORTED_DATA_TYPE
AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10).
Data as JSON: /api/errors/97e70c396944e7fb.
Report an issue: GitHub.