{"record":{"id":"90270a4cc89f6a24","repo":"flowable/flowable-engine","slug":"couldn-t-serialize-value-value-in-variable","errorCode":null,"errorMessage":"Couldn't serialize value '${value}' in variable '${name}'","messagePattern":"Couldn't serialize value '(.+?)' in variable '(.+?)'","errorType":"exception","errorClass":"FlowableException","httpStatus":null,"severity":"error","filePath":"modules/flowable-variable-service/src/main/java/org/flowable/variable/service/impl/types/SerializableType.java","lineNumber":146,"sourceCode":"            if (!Arrays.equals(refreshedOriginalBytes, bytes)) {\n                variableInstanceEntity.setBytes(bytes);\n                valueChanged = true;\n            }\n        }\n        return valueChanged;\n    }\n\n    public byte[] serialize(Object value, ValueFields valueFields) {\n        if (value == null) {\n            return null;\n        }\n        ByteArrayOutputStream baos = new ByteArrayOutputStream();\n        ObjectOutputStream oos = null;\n        try {\n            oos = createObjectOutputStream(baos);\n            oos.writeObject(value);\n        } catch (Exception e) {\n            throw new FlowableException(\"Couldn't serialize value '\" + value + \"' in variable '\" + valueFields.getName() + \"'\", e);\n        } finally {\n            IoUtil.closeSilently(oos);\n        }\n        return baos.toByteArray();\n    }\n\n    public Object deserialize(byte[] bytes, ValueFields valueFields) {\n        ByteArrayInputStream bais = new ByteArrayInputStream(bytes);\n        try {\n            ObjectInputStream ois = createObjectInputStream(bais);\n            Object deserializedObject = ois.readObject();\n\n            return deserializedObject;\n        } catch (Exception e) {\n            throw new FlowableException(\"Couldn't deserialize object in variable '\" + valueFields.getName() + \"'\", e);\n        } finally {\n            IoUtil.closeSilently(bais);\n        }","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-variable-service/src/main/java/org/flowable/variable/service/impl/types/SerializableType.java#L128-L164","documentation":"Flowable's SerializableType serializes a variable value to bytes via Java ObjectOutputStream before persisting it. This FlowableException wraps any exception thrown during writeObject (NotSerializableException, IOException, etc.), naming the value and the variable. It means the value stored in the variable cannot be Java-serialized.","triggerScenarios":"Setting a process/execution/task variable (or a transient variable) whose runtime type does not implement java.io.Serializable, or whose fields reference non-serializable objects; serialization stream corruption or a custom writeObject throwing; createObjectOutputStream failing.","commonSituations":"Putting a Spring service bean, an InputStream/Connection, a lambda capturing a non-serializable context, or a Mockito mock into a process variable; an object graph that gained a non-serializable field after a dependency upgrade.","solutions":["Make the variable's class (and every object it references transitively) implement java.io.Serializable","Store only small, serializable data (ids, JSON strings) in variables instead of live objects; re-fetch objects in delegates","Inspect the cause: NotSerializableException names the first offending class — fix that class or mark the field transient","If the object is huge or non-serializable by design, keep it out of the variable scope (pass via external store and put only the key in the variable)"],"exampleFix":"// before\nruntimeService.setVariable(executionId, \"customer\", new CustomerService());\n// after\nruntimeService.setVariable(executionId, \"customerId\", customer.getId());","handlingStrategy":"try-catch","validationCode":"private static boolean isSerializable(Object o) {\n    if (o instanceof Serializable) return true;\n    try { new ObjectOutputStream(new ByteArrayOutputStream()).writeObject(o); return true; }\n    catch (NotSerializableException e) { return false; }\n    catch (IOException e) { return false; }\n}","typeGuard":"if (!(value instanceof java.io.Serializable)) {\n    throw new IllegalArgumentException(\"Variable value must implement Serializable: \" + value.getClass());\n}","tryCatchPattern":"try {\n    runtimeService.setVariable(executionId, name, value);\n} catch (FlowableException e) {\n    if (e.getCause() instanceof NotSerializableException) {\n        log.error(\"Variable {} value not serializable: {}\", name, e.getCause().getMessage());\n    }\n    throw e;\n}","preventionTips":["Only store primitives, Strings, and explicit Serializable DTOs in process variables","Run a unit test that serializes every domain class used as a variable value","Mark non-serializable fields transient and re-resolve them after deserialization","Store large objects externally and keep only the key in the variable"],"tags":["serialization","java","variables"],"backgroundTag":"json-serialization-failed","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-18T11:17:12.947Z"}