{"record":{"id":"80b023f1422bb5ae","repo":"flowable/flowable-engine","slug":"failed-to-serialize-to-a-restvariable-instance-80b023","errorCode":null,"errorMessage":"Failed to serialize to a RestVariable instance","messagePattern":"Failed to serialize to a RestVariable instance","errorType":"http","errorClass":"FlowableIllegalArgumentException","httpStatus":400,"severity":"error","filePath":"modules/flowable-rest/src/main/java/org/flowable/rest/service/api/runtime/task/TaskVariableCollectionResource.java","lineNumber":145,"sourceCode":"\n        Object result = null;\n        if (request instanceof MultipartHttpServletRequest) {\n            result = setBinaryVariable((MultipartHttpServletRequest) request, task, true);\n        } else {\n\n            List<RestVariable> inputVariables = new ArrayList<>();\n            List<RestVariable> resultVariables = new ArrayList<>();\n            result = resultVariables;\n\n            try {\n                @SuppressWarnings(\"unchecked\")\n                List<Object> variableObjects = (List<Object>) objectMapper.readValue(request.getInputStream(), List.class);\n                for (Object restObject : variableObjects) {\n                    RestVariable restVariable = objectMapper.convertValue(restObject, RestVariable.class);\n                    inputVariables.add(restVariable);\n                }\n            } catch (Exception e) {\n                throw new FlowableIllegalArgumentException(\"Failed to serialize to a RestVariable instance\", e);\n            }\n\n            if (inputVariables == null || inputVariables.size() == 0) {\n                throw new FlowableIllegalArgumentException(\"Request did not contain a list of variables to create.\");\n            }\n\n            RestVariableScope sharedScope = null;\n            RestVariableScope varScope = null;\n            Map<String, Object> variablesToSet = new HashMap<>();\n\n            for (RestVariable var : inputVariables) {\n                // Validate if scopes match\n                varScope = var.getVariableScope();\n                if (var.getName() == null) {\n                    throw new FlowableIllegalArgumentException(\"Variable name is required\");\n                }\n\n                if (varScope == null) {","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-rest/src/main/java/org/flowable/rest/service/api/runtime/task/TaskVariableCollectionResource.java#L127-L163","documentation":"The bulk create-variables endpoint failed to deserialize the request InputStream into RestVariable objects. Any exception during readValue/convertValue (malformed JSON, wrong shape, bad types) is wrapped in FlowableIllegalArgumentException with this message.","triggerScenarios":"POST /runtime/tasks/{taskId}/variables with a body that is not valid JSON or whose elements do not map to RestVariable (e.g. array of plain values instead of objects, unknown type identifiers, wrong Content-Type).","commonSituations":"Sending form-data or XML instead of JSON; passing [{\"name\":\"v\",\"value\":1},{\"x\":2}] with malformed items; charset/BOM issues; custom variable types unregistered with the ObjectMapper.","solutions":["Validate the request body is well-formed JSON: an array of objects each with at least \"name\"","Send Content-Type: application/json","Test the payload with a JSON linter / curl before calling the API"],"exampleFix":"// before\n[\"var1\", \"var2\"]\n// after\n[{\"name\": \"var1\", \"value\": 1}, {\"name\": \"var2\", \"value\": 2}]","handlingStrategy":"validation","validationCode":"let parsed; try { parsed = JSON.parse(JSON.stringify(payload)); } catch (e) { throw new Error('Payload is not valid JSON: ' + e.message); } if (!Array.isArray(parsed) || !parsed.every(v => typeof v === 'object' && v !== null && v.name)) { throw new Error('Body must be an array of RestVariable objects'); }","typeGuard":"function isRestVariableArray(v) { return Array.isArray(v) && v.every(x => typeof x === 'object' && x !== null && typeof x.name === 'string'); }","tryCatchPattern":"try { await api.post(`/runtime/tasks/${taskId}/variables`, payload); } catch (e) { if (e.response && e.response.status === 400 && /Failed to serialize/.test(e.response.data.message || '')) { logPayloadForDebug(payload); } throw e; }","preventionTips":["Send Content-Type: application/json","Lint/validate JSON bodies before sending","Keep payload shapes aligned with the RestVariable model (name, value, type, variableScope)"],"tags":["rest-api","json","serialization"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-18T16:30:33.424Z"}