flowable/flowable-engine · error · ActivitiException
Couldn't serialize value '' in variable ''
Error message
Couldn't serialize value '' in variable ''
What it means
Thrown by SerializableType.serialize when Java serialization of a variable value fails inside ObjectOutputStream. The original exception (NotSerializableException, IOException, etc.) is attached as the cause.
Solutions
- Make the value's class (and all reachable fields) implement java.io.Serializable.
- Mark non-serializable fields transient or restructure the object graph.
- Store only a small DTO/identifier in the variable instead of a large live object.
- Inspect the cause chain (NotSerializableException names the offending class) and fix that class.
- Declare the variable with a custom VariableType (e.g. JSON type) instead of Java serialization.
Example fix
// before
public class OrderData {
private transient DataSource ds; // fine
private Helper helper; // Helper not Serializable -> throws
}
// after
public class OrderData implements Serializable {
private Helper helper; // Helper now implements Serializable
} Defensive patterns
Strategy: validation
Validate before calling
if (!(value instanceof java.io.Serializable)) throw new IllegalArgumentException("Variable value of type " + value.getClass() + " is not Serializable");
new java.io.ObjectOutputStream(new java.io.ByteArrayOutputStream()).close(); // warm-up not required; rely on instanceof check Type guard
boolean isSerializable(Object v) { return v instanceof java.io.Serializable; } Try / catch
try { runtimeService.setVariable(id, "order", order); } catch (ActivitiException e) { log.error("Failed to serialize variable 'order': {}", e.getCause(), e); } Prevention
- Implement Serializable on all variable DTOs and their nested types
- Mark non-serializable fields transient
- Keep variables small and value-like, not live service objects
- Prefer JSON/custom variable types for long-lived data
When it happens
Trigger: Setting a process variable whose type falls back to the 'serializable' variable type but whose class does not implement Serializable, or whose object graph contains non-serializable members; serialization infrastructural IO failures.
Common situations: Storing Spring beans, EntityManager references, or streams in variables; a referenced class changed and is no longer Serializable; third-party object graphs containing non-serializable fields.
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
- couldn't find a variable type that is able to serialize
- Couldn't serialize value
- Couldn't deserialize object in variable
- Empty object, no variables can be set
- Error getting variable
AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11).
Data as JSON: /api/errors/d08ad1cf44f2fdef.
Report an issue: GitHub.
Appendix: source
Thrown at modules/flowable5-engine/src/main/java/org/activiti/engine/impl/variable/SerializableType.java:105
.getDbSqlSession()
.addDeserializedObject(new DeserializedObject(this, valueFields.getCachedValue(), byteArray, (VariableInstanceEntity) valueFields));
}
}
super.setValue(byteArray, valueFields);
}
public byte[] serialize(Object value, ValueFields valueFields) {
if (value == null) {
return null;
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = null;
try {
oos = createObjectOutputStream(baos);
oos.writeObject(value);
} catch (Exception e) {
throw new ActivitiException("Couldn't serialize value '" + value + "' in variable '" + valueFields.getName() + "'", e);
} finally {
IoUtil.closeSilently(oos);
}
return baos.toByteArray();
}
public Object deserialize(byte[] bytes, ValueFields valueFields) {
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
try {
ObjectInputStream ois = createObjectInputStream(bais);
Object deserializedObject = ois.readObject();
return deserializedObject;
} catch (Exception e) {
throw new ActivitiException("Couldn't deserialize object in variable '" + valueFields.getName() + "'", e);
} finally {
IoUtil.closeSilently(bais);
}View on GitHub (pinned to d6d39ce1c6)