{"record":{"id":"21c7cfe4ac24fc29","repo":"flowable/flowable-engine","slug":"failed-to-serialize-to-a-restvariable-instance-21c7cf","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-cmmn-rest/src/main/java/org/flowable/cmmn/rest/service/api/runtime/task/TaskVariableCollectionResource.java","lineNumber":146,"sourceCode":"        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                \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 didn't 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":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-rest/src/main/java/org/flowable/cmmn/rest/service/api/runtime/task/TaskVariableCollectionResource.java#L128-L164","documentation":"FlowableIllegalArgumentException thrown by createTaskVariable when the JSON array of variable objects in the request body cannot be converted to RestVariable instances via Jackson's objectMapper.convertValue. Any structural mismatch (wrong element shapes, unexpected field types) is caught and rethrown with this message and the underlying exception as cause.","triggerScenarios":"POST /cmmn-runtime/tasks/{taskId}/variables with a body whose 'variables' array contains elements that don't map to RestVariable — e.g. a bare string instead of an object, or fields with incompatible value types.","commonSituations":"Clients posting single objects instead of arrays; wrong JSON shape due to library version changes; copy-paste errors mixing the binary and JSON endpoints; non-JSON content types.","solutions":["Send an array of RestVariable-shaped objects: [{\"name\":\"..\",\"type\":\"..\",\"value\":..}]","Inspect the cause in the server log for the exact Jackson path error","Validate JSON structure against the Flowable REST variable schema before sending","Ensure Content-Type is application/json"],"exampleFix":"// before\n{\"variables\": \"name1\"}\n// after\n{\"variables\": [{\"name\":\"name1\",\"type\":\"string\",\"value\":\"x\"}]}","handlingStrategy":"validation","validationCode":"const isRestVariable = (v) => v != null && typeof v === 'object' && !Array.isArray(v) && typeof v.name === 'string';\nif (!Array.isArray(vars) || !vars.every(isRestVariable)) throw new Error('variables must be an array of {name,type,value} objects');","typeGuard":"const isRestVariable = (v) => v != null && typeof v === 'object' && !Array.isArray(v) && typeof v.name === 'string';","tryCatchPattern":"try { await createVariables(payload) } catch (e) { if (/Failed to serialize to a RestVariable/.test(e.message)) console.error('malformed variable payload', e.cause); throw e; }","preventionTips":["Send proper JSON arrays of variable objects","Validate payloads against the Flowable REST variable schema","Ensure Content-Type: application/json"],"tags":["rest","json","jackson","validation"],"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-14T05:17:10.506Z"}