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

  1. Make the value's class (and all reachable fields) implement java.io.Serializable.
  2. Mark non-serializable fields transient or restructure the object graph.
  3. Store only a small DTO/identifier in the variable instead of a large live object.
  4. Inspect the cause chain (NotSerializableException names the offending class) and fix that class.
  5. 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

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


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)